[Zope] Newbie: creating objects programmatically

Dmitry Dembinsky dmitry@deluxoft.com
Wed, 14 May 2003 13:21:55 +0200


> ...I read the ZPT source and figured I could do 
> the following:
> 
> instance.manage_addProduct['PageTemplates'].manage_addPageTemp
> late('index_html')
> instance['index_html'].write(instance.memberIndex.document_src(self))
> 
> but no, I get:
> 
> Error Type: Unauthorized
> Error Value: You are not allowed to access document_src in 
> this context
> 
> I am logged in as 'manager'. I have tried:
> 
> instance['index_html'].write(str(instance.memberIndex))
>   where memberIndex is a regular file and this works fine, 
> but I want to use a model ZPT.
> 

1) method document_src() requires no parameters
(self is passed implicitly by python)
So you may write 
context['index_html'].write(context.memberIndex.document_src())

2) To create a page template with a content, you may pass it in
constructor:
container.manage_addProduct['PageTemplates'].manage_addPageTemplate('ind
ex_html', 
text=context.memberIndex.document_src())

Enjoy :)

Dmitry