Okay... I'll admit it: I'm one of those who only knows about Python because of Zope. I am working with Formulator, and need a method to return a list of properties. I have DTML code that returns the list <dtml-call "REQUEST.set('tmp',{})"> <dtml-in expr="_.sequence.sort(PARENTS[0].objectValues(['STX_Document']), (('topic', 'nocase'), ('title', 'cmp'),) )"> <dtml-call "REQUEST['tmp'].update({topic:''})"> </dtml-in> <dtml-in "REQUEST['tmp'].keys()"> <dtml-var sequence-item> </dtml-in> The values of the "topic" property are returned. But when called as an override method for a Formulator MultiListField, I get this error: Zope Error Zope has encountered an error while publishing this resource. Error Type: NameError Error Value: global name 'REQUEST' is not defined File /usr/local/Zope/lib/python/DocumentTemplate/DT_Util.py, line 231, in eval (Object: form.topic.render()) (Info: form) File <string>, line 2, in f (Object: guarded_getattr) File /usr/local/Zope/lib/python/Products/Formulator/Field.py, line 178, in render (Object: topic) File /usr/local/Zope/lib/python/Products/Formulator/Field.py, line 156, in _render_helper (Object: topic) File /usr/local/Zope/lib/python/Products/Formulator/Widget.py, line 451, in render File /usr/local/Zope/lib/python/Products/Formulator/Widget.py, line 376, in render_items File /usr/local/Zope/lib/python/Products/Formulator/Field.py, line 107, in get_value (Object: topic) File /usr/local/Zope/lib/python/Products/Formulator/MethodField.py, line 40, in __call__ File /usr/local/Zope-2.4.3-linux2-x86/lib/python/OFS/DTMLMethod.py, line 192, in __call__ (Object: topics) File /usr/local/Zope-2.4.3-linux2-x86/lib/python/DocumentTemplate/DT_String.py, line 546, in __call__ (Object: topics) File /usr/local/Zope/lib/python/DocumentTemplate/DT_Util.py, line 231, in eval (Object: REQUEST.set('tmp',{})) (Info: REQUEST) File <string>, line 2, in f (Object: guarded_getattr) NameError: (see above) Okay -- I can figure out that it's because there's environment (namespace stuff) when DTML is called as a method that just doesn't work. So it needs to be rewritten as a Python script, but I'm a Python neophyte, so I'm asking (pleading.... begging....) for help. Thanx in advance
cgreen writes:
... DTML object ... The values of the "topic" property are returned. But when called as an override method for a Formulator MultiListField, I get this error:
Zope Error
Zope has encountered an error while publishing this resource.
Error Type: NameError Error Value: global name 'REQUEST' is not defined I guess, it is a standard error:
Whenever DTML objects are called explicitly, they should get 2 positional parameters. These parameters are necessary to provide the context to the DTML object call. In your case, the context is obviously missing. Please read the section "Calling DTML objects" in <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> to learn more. Dieter
Dieter; Thanks for the reply.... after I posted the original question, I got off my lazy butt, searched a few sites, and came up with this: (hmmm...... a new acronym, maybe -- GOYLA?? [Get Off Your Lazy A--]) results=[] for object in context.objectValues('STX_Document'): if object.getProperty('topic') != '': if tuple not in results: results.append(object.topic) results.sort() return results as a python script, instead of the DTML method: <dtml-call "REQUEST.set('tmp',{})"> <dtml-in expr="_.sequence.sort(PARENTS[0].objectValues(['STX_Document']), (('topic', 'nocase'), ('title', 'cmp'),) )"> <dtml-call "REQUEST['tmp'].update({topic:''})"> </dtml-in> <dtml-in "REQUEST['tmp'].keys()"> <dtml-var sequence-item> </dtml-in> Just thought I'd share this for anyone following the thread.... I hate seeing questions asked in newsgroups without answers......
cgreen writes:
... DTML object ... The values of the "topic" property are returned. But when called as an override method for a Formulator MultiListField, I get this error:
Zope Error
Zope has encountered an error while publishing this resource.
Error Type: NameError Error Value: global name 'REQUEST' is not defined I guess, it is a standard error:
Whenever DTML objects are called explicitly, they should get 2 positional parameters. These parameters are necessary to provide the context to the DTML object call.
In your case, the context is obviously missing.
Please read the section "Calling DTML objects" in
<http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>
to learn more.
Dieter
participants (2)
-
cgreen -
Dieter Maurer