[Zope] Generic add page template fails

Josef Meile jmeile@hotmail.com
Mon, 21 Jul 2003 17:24:32 +0200


Hi,

I'm trying to do a generic add page template where I don't
have to write the class name. The name will be taken from
an attribute of the template object. If you see the file
OFS/Image.py, you will see something like this:

manage_addImageForm=DTMLFile('dtml/imageAdd',globals(),Kind='Image',kind='im
age')

The attribute Kind is called from OFS/dtml/imageAdd.dtml like this:

<dtml-var "manage_form_title(this(), _,form_title='Add %s' %
Kind,help_product='OFSP',help_topic='File_Add.stx')">

And if you continue scrolling this file, you'll see something

much better:

<form action="manage_add<dtml-var Kind>"
method="post"enctype="multipart/form-data">



I'm trying something similar with ZPT, but it fails:

in my class I do:

manage_addBoringForm=PageTemplateFile('ZPT/addBoring',globals(),Kind='Boring
',kind='boring')
manage_addBoringForm._owner=None

and in the ZPT File I have tried:

<h1 tal:define="Kind xxx/Kind;pageTitle python:here.manage_form_title(here,
request,form_title='Add %s' % Kind)"
tal:replace="structure pageTitle">Add myClass
</h1>

Where xxx is 'here', or 'template', or 'request'
In all of the cases it returns:

Traceback (innermost last):
Module ZPublisher.Publish, line 98, in publish
Module ZPublisher.mapply, line 88, in mapply
Module ZPublisher.Publish, line 39, in call_object
Module Shared.DC.Scripts.Bindings, line 252, in __call__
Module Shared.DC.Scripts.Bindings, line 283, in _bindAndExec
Module Products.PageTemplates.PageTemplateFile, line 96, in _exec
Module Products.PageTemplates.PageTemplate, line 95, in pt_render
- <PageTemplateFile at /pythonTest/>
Module TAL.TALInterpreter, line 200, in __call__
Module TAL.TALInterpreter, line 244, in interpret
Module TAL.TALInterpreter, line 473, in do_setLocal_tal
Module Products.PageTemplates.TALES, line 220, in evaluate
- URL: addBoring
- Line 2, Column 0
- Expression: standard:'xxx/Kind'
- Names:
{'container': <__FactoryDispatcher__ instance at 01C46FF0>,
'default': <Products.PageTemplates.TALES.Default instance at 00EDBF9C>,
'xxx': <__FactoryDispatcher__ instance at 01C46FF0>,
'loop': <SafeMapping instance at 01D9C6A8>,
'modules': <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter
instance at 00EE554C>,
'nothing': None,
'options': {'args': ()},
'repeat': <SafeMapping instance at 01D9C6A8>,
'request': <HTTPRequest,
URL=http://localhost:8080/pythonTest/manage_addProduct/Boring/addBoring>,
'root': <Application instance at 01B2A560>,
'template': <PageTemplateFile at /pythonTest/>,
'traverse_subpath': [],
'user': admin}
Module Products.PageTemplates.Expressions, line 206, in __call__
Module Products.PageTemplates.Expressions, line 194, in _eval
Module Products.PageTemplates.Expressions, line 150, in _eval
- __traceback_info__: xxx
Module Products.PageTemplates.Expressions, line 360, in restrictedTraverse
- __traceback_info__: {'path': ['Kind'], 'TraversalRequestNameStack': []}

AttributeError: Kind

It seems like this attribute isn't stored on my Template. Does somebody
know how to do something similar with ZPT?

Thanks in advanced,
Josef