[Zope] Re: Adding attributes to PageTemplateFile
Josef Meile
jmeile at hotmail.com
Tue Sep 16 07:59:23 EDT 2003
> Simplest way I can think of is:
>
> software_type_list = [
> {'value': 'OS'},
> {'value': 'Applikation'},
> {'value': 'Service'}
> ]
>
> _addSoftwareForm = PageTemplateFile("www/software_form_add",
> globals())
>
> def manage_addSoftwareForm(self,*args,**kw):
> kw['software_type_list']=software_type_list
> return self._addSoftwareForm(*args,**kw)
>
> they can then be used as:
>
> tal:repeat="x options/software_type_list"
Just one question more about this:
If you use it inside the class definition, it will work
because "self" it's an instance of the class, so it has
access to the class attributes, but if it's outside, like
the manage_addForm method, it won't:
_addFooForm=PageTemplateFile('zpt/Foo_Add',globals())
_addFooForm._owner=None
def manage_addFooForm(self,*args,**kw):
"""manage_addFooForm method"""
kw['Kind']='Foo'
return self._addFooForm(*args,**kw)
class Foo(...):
.
.
.
I get this error:
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 Products.Foo.Foo, line 82, in manage_addFooForm
AttributeError: _addFooForm
I think the cause is that "self" doesn't reffers to the class
module here. It reffers to the object from which it was called. On
the other hand, if I remove self and just return _addFooForm:
def manage_addFooForm(self,*args,**kw):
"""manage_addFooForm method"""
kw['Kind']='Foo'
return _addFooForm(*args,**kw)
I get this error:
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 Products.Foo.Foo, line 81, in manage_addFooForm
Module Shared.DC.Scripts.Bindings, line 252, in __call__
Module Shared.DC.Scripts.Bindings, line 281, in _bindAndExec
Module Shared.DC.Scripts.Bindings, line 1, in ?
Module Shared.DC.Scripts.Bindings, line 232, in _getTraverseSubpath
AttributeError: other
Watching the Shared/DC/Scripts/Bindings.py code, you can
see that the offending code is in the method _getTraverseSubpath:
return self.REQUEST.other.get('traverse_subpath', [])
How can I get this working? Any ideas?
Thanks in advanced,
Josef
More information about the Zope
mailing list