Passing keyword options to PageTemplateFile?
I'm creating a Python product ('MyClass') and attempting to use Zope Page Templates for the 'manage_*' forms. In my manage_addMyClassForm, I want the ZPT to render a multiple selection list (of 'categories') using a tal:repeat statement which accesses 'categories' through the 'options' ZPT name. My problem lies in passing the 'categories' sequence into the ZPT (via 'options') from the MyClass.py module. Here's what I have so far: - MyClass directory which contains __init__.py, MyClass.py, and a sub-folder ('www') which contains the ZPT forms. - MyClass.py defines MyClass and the 'categories' sequence (at the global level). It also instantiates a Page Template object like so: preAddForm = PageTemplateFile('www/manage_addMyClassForm', globals()) - Then, I attempt (and fail) to create my manage_addMyClassForm Page Template this way (trying to use PageTemplate.__call__): manage_addMyClassForm = preAddForm(categories = allCategories) My intention is that the above line passes 'categories' into the Page Template as one of the 'options' keyword arguments so that I can repeat over the sequence like: tal:repeat="category options/categories" It doesn't work and I thank you in advance if you have any advice. Below is the error I get when I start up Zope and it fails to import the product: 2003-02-12T13:13:29 ERROR(200) Zope Could not import Products.MyClass Traceback (innermost last): File C:\Zope1\lib\python\OFS\Application.py, line 541, in import_product File C:\Zope1\Products\MyClass\__init__.py, line 1, in ? File C:\Zope1\Products\MyClass\MyClass.py, line 42, in ? (Object: PageTemplate) File C:\Zope1\lib\python\Shared\DC\Scripts\Bindings.py, line 252, in __call__ (Object: manage_addMyClassForm) File C:\Zope1\lib\python\Shared\DC\Scripts\Bindings.py, line 281, in _bindAndExec (Object: manage_addMyClassForm) File <string>, line 1, in ? File C:\Zope1\lib\python\Shared\DC\Scripts\Bindings.py, line 232, in _getTraverseSubpath (Object: manage_addMyClassForm) AttributeError: other Jon Whitener Detroit Michigan USA
Jon Whitener wrote at 2003-2-12 13:34 -0500:
I'm creating a Python product ('MyClass') and attempting to use Zope Page Templates for the 'manage_*' forms. In my manage_addMyClassForm, I want the ZPT to render a multiple selection list (of 'categories') using a tal:repeat statement which accesses 'categories' through the 'options' ZPT name.
My problem lies in passing the 'categories' sequence into the ZPT (via 'options') from the MyClass.py module. Here's what I have so far:
Me too, I really miss the ability to pass in parameters to ZPT's at instantiation time (what I can easily do with DTML objects). I work around this lack through wrapper methods: .... template= PageTemplateFile def T1(self): return self.template(a1= v1, a2= v2, ...) def T2(self): return self.template(b1= w1, b2= w2, ....) Dieter
Dieter Maurer wrote:
My problem lies in passing the 'categories' sequence into the ZPT (via 'options') from the MyClass.py module. Here's what I have so far:
Me too, I really miss the ability to pass in parameters to ZPT's at instantiation time (what I can easily do with DTML objects).
Maybe that's a feature that could be added? cheers, Chris
Chris Withers wrote at 2003-2-14 08:59 +0000:
Dieter Maurer wrote:
My problem lies in passing the 'categories' sequence into the ZPT (via 'options') from the MyClass.py module. Here's what I have so far:
Me too, I really miss the ability to pass in parameters to ZPT's at instantiation time (what I can easily do with DTML objects).
Maybe that's a feature that could be added? Almost surely.
It's just a question who does it.. Dieter
Dieter Maurer wrote:
Maybe that's a feature that could be added?
Almost surely.
It's just a question who does it..
How do we go about finding out how many people would want this feature and what the best way is to implement it? cheers, Chris
Regarding how many people: I say that any relatively new users of Zope would prefer to need only one templating language instead of two. I wish my skill at writing ZPTs extended throughout Zope so that I wouldn't need to write DTML. As far as implementation, I found this checkin from Kapil Thangavelu regarding "Setting Up Contexts" for Page Templates in Zope 3. (About the middle of the page.) http://mail.python.org/pipermail/zope3-checkins/2002-December/002030.html I'm no Zope developer, but I thought that info might help. Jon Chris Withers wrote:
Dieter Maurer wrote:
Maybe that's a feature that could be added? Almost surely.
It's just a question who does it..
How do we go about finding out how many people would want this feature and what the best way is to implement it?
cheers,
Chris
participants (3)
-
Chris Withers -
Dieter Maurer -
Jon Whitener