Platform information: Zope version: Zope 2.2.1b1 (binary release, python 1.5.2, linux2-x86) Python version: 1.5.2 (#10, Dec 6 1999, 12:16:27) [GCC 2.7.2.3] System Platform: linux2 ----------------------------------------------------------------------------- Notice in add_weekly the <dtml-call day_list>. It does nothing but with out it I get this traceback: Zope Error Zope has encountered an error while publishing this resource. Error Type: AttributeError Error Value: __getitem__ Traceback (innermost last): File /usr/local/zope/2.2/lib/python/ZPublisher/Publish.py, line 222, in publish_module File /usr/local/zope/2.2/lib/python/ZPublisher/Publish.py, line 187, in publish File /usr/local/zope/2.2/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook (Object: Traversable) File /usr/local/zope/2.2/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/local/zope/2.2/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: add_weekly) File /usr/local/zope/2.2/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: add_weekly) File /usr/local/zope/2.2/lib/python/OFS/DTMLMethod.py, line 172, in __call__ (Object: add_weekly) File /usr/local/zope/2.2/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__ (Object: add_weekly) File /usr/local/zope/2.2/lib/python/DocumentTemplate/DT_In.py, line 691, in renderwob (Object: done_list) File /usr/local/zope/2.2/lib/python/DocumentTemplate/DT_Util.py, line 337, in eval (Object: _['sequence-item'] in day_list) (Info: day_list) File <string>, line 0, in ? AttributeError: (see above) ------------------------------------------------------------------ DTML METHOD: period_begin Selects a set of dates in the past 41 days that are either the first day of the month or a Sunday. Returns the list. <dtml-call "REQUEST.set('first_day', ZopeTime() )"> <dtml-call "REQUEST.set('to_day', ZopeTime() )"> <dtml-call "REQUEST.set('day_list', [])"> <dtml-in "_.range(0,40)"> <dtml-call "REQUEST.set('rpt_date', first_day - _['sequence-item'])"> <dtml-if "rpt_date.lessThanEqualTo( to_day )"> <dtml-if "(rpt_date.day()==1) or rpt_date.dow()==0"> <dtml-call "day_list.append(rpt_date.strftime('%Y / %m / %d'))"> </dtml-if> </dtml-if> </dtml-in> <dtml-return day_list> ------------------------------------------------------- DTML METHOD: add_weekly Input form to report weekly activities. <dtml-call "REQUEST.set('day_list', period_begin)"> <dtml-call "REQUEST.set('done_list', [])"> <dtml-in "objectValues(['DTML Document'])"> <dtml-if "doc_type == 'weekly'"> <dtml-call "done_list.append(week_begin.strftime('%Y / %m / %d'))"> </dtml-if> </dtml-in> <dtml-call day_list> <dtml-in done_list> <dtml-if "_['sequence-item'] in day_list"> <dtml-call "day_list.remove(_['sequence-item'])"> </dtml-if> </dtml-in> .... more code here that uses day_list in a <SELECT></SELECT> and takes more form input. ... Is this a bug or should I clean up my code??? <s> -- Tim Cook -- FreePM Project Coordinator http://www.freepm.org OS Health Care Alliance Supporter http://www.oshca.org
Tim Cook wrote:
-----------------------------------------------------------------------------
Notice in add_weekly the <dtml-call day_list>. It does nothing but with out it I get this traceback:
Zope Error
Zope has encountered an error while publishing this resource.
Error Type: AttributeError Error Value: __getitem__
Traceback (innermost last): File /usr/local/zope/2.2/lib/python/ZPublisher/Publish.py, line
(Object: done_list) File /usr/local/zope/2.2/lib/python/DocumentTemplate/DT_Util.py, line 337, in eval (Object: _['sequence-item'] in day_list) (Info: day_list) File <string>, line 0, in ? AttributeError: (see above)
------------------------------------------------------------------ DTML METHOD: period_begin Selects a set of dates in the past 41 days that are either the first day of the month or a Sunday. Returns the list.
<snip>
------------------------------------------------------- DTML METHOD: add_weekly Input form to report weekly activities.
--------->>>>>> <dtml-call "REQUEST.set('day_list', period_begin)">
<dtml-call "REQUEST.set('done_list', [])">
<dtml-call day_list>
<dtml-in done_list> <dtml-if "_['sequence-item'] in day_list"> <dtml-call "day_list.remove(_['sequence-item'])"> </dtml-if> </dtml-in>
.... more code here that uses day_list in a <SELECT></SELECT> and takes more form input. ...
Is this a bug or should I clean up my code??? <s>
When you call request.set your setting daylist to the method not the results of the method. try switching it to <dtml-call "REQUEST.set('day_list', period_begin(_.None, _))"> Kapil
Kapil Thangavelu wrote:
Tim Cook wrote:
-----------------------------------------------------------------------------
Notice in add_weekly the <dtml-call day_list>. It does nothing but with out it I get this traceback:
Zope Error
Zope has encountered an error while publishing this resource.
Error Type: AttributeError Error Value: __getitem__
Traceback (innermost last): File /usr/local/zope/2.2/lib/python/ZPublisher/Publish.py, line
(Object: done_list) File /usr/local/zope/2.2/lib/python/DocumentTemplate/DT_Util.py, line 337, in eval (Object: _['sequence-item'] in day_list) (Info: day_list) File <string>, line 0, in ? AttributeError: (see above)
------------------------------------------------------------------ DTML METHOD: period_begin Selects a set of dates in the past 41 days that are either the first day of the month or a Sunday. Returns the list.
<snip>
------------------------------------------------------- DTML METHOD: add_weekly Input form to report weekly activities.
--------->>>>>> <dtml-call "REQUEST.set('day_list', period_begin)">
<dtml-call "REQUEST.set('done_list', [])">
<dtml-call day_list>
<dtml-in done_list> <dtml-if "_['sequence-item'] in day_list"> <dtml-call "day_list.remove(_['sequence-item'])"> </dtml-if> </dtml-in>
.... more code here that uses day_list in a <SELECT></SELECT> and takes more form input. ...
Is this a bug or should I clean up my code??? <s>
When you call request.set your setting daylist to the method not the results of the method. try switching it to
<dtml-call "REQUEST.set('day_list', period_begin(_.None, _))">
Kapil
Hmm, thanks. I ran a little test stub that set day_list both ways with the var rendered each time. They returned exactly the same list. But, your suggestion did correct the problem that I had. So, as a newbie warning to others just because it renders correctly doesn't mean that it's behavior is going to be correct in a programmatic sense. So, why did the dtml-call or dtml-var calls cause the add_weekly method to work? (Too many years of procedural code and not enough OOP zen!). -- Tim Cook -- FreePM Project Coordinator http://www.freepm.org OS Health Care Alliance Supporter http://www.oshca.org
Tim Cook wrote:
Kapil Thangavelu wrote:
--------->>>>>> <dtml-call "REQUEST.set('day_list', period_begin)">
<dtml-call "REQUEST.set('done_list', [])">
When you call request.set your setting daylist to the method not the results of the method. try switching it to
<dtml-call "REQUEST.set('day_list', period_begin(_.None, _))">
Kapil
But, your suggestion did correct the problem that I had.
So, as a newbie warning to others just because it renders correctly doesn't mean that it's behavior is going to be correct in a programmatic sense.
So, why did the dtml-call or dtml-var calls cause the add_weekly method to work?
(Too many years of procedural code and not enough OOP zen!).
If it makes you feel any better it has nothing to do with your OOP Zen. This exists as an artifact of the idiosyncracies of DTML. so take a dtml-var statement <dtml-var foobar> or <dtml-var "foobar"> Most DTML tags automajically call an item and marshall in the proper arguements. if you escape from pure dtml to pythonish dtml "", than you need to make your calls explicity since you're writing in a safe sub dialect of python not in DTML. the args you're passing in if memory serve, are the client object, a mapping object, and keyword args. taking the above calls as example and assuming foobar is a dtml method that returns a list containing [1,2,3,4]. than the first method would render the list and the second would render a hidden tag (view source to look at it) something like <DTML METHOD OB MEMORY REF>, not what you what wanted. The solution is first to call it like a python function (), and to pass it the default args. <dtml-var "foobar(_.None, _)"> this passes it None for a client, and the current namespace as the mapping, and no keyword args. hope that was clearer than mud. Kapil
Kapil Thangavelu wrote:
<dtml-var "foobar(_.None, _)">
this passes it None for a client, and the current namespace as the mapping, and no keyword args.
hope that was clearer than mud.
So the 'key' to this confusion is that we are passing the 'Zope namespace' to the python method (function) call? (Which I guess is REALLY just a Python namespace anyway?) Maybe I should study the Python source where this occurs. It's still VERY foggy! <g> -- Tim Cook -- FreePM Project Coordinator http://www.freepm.org OS Health Care Alliance Supporter http://www.oshca.org
Tim Cook wrote:
Kapil Thangavelu wrote:
<dtml-var "foobar(_.None, _)">
this passes it None for a client, and the current namespace as the mapping, and no keyword args.
hope that was clearer than mud.
So the 'key' to this confusion is that we are passing the 'Zope namespace' to the python method (function) call? (Which I guess is REALLY just a Python namespace anyway?)
the highlights. one is DTML tags automatically calls and give the proper args to what they call. the second is that when you not in pure DTML, you need to call methods explicitly and pass them args they might need. note the namespace is just a glorified mapping(dictionary) parts of which, ie the REQUEST are built dynamically during the Publishing process. you could pass the method any dictionary. but since you're accessing the DateTime module in your function you need to access it through the namespace. again, all of this is more a function of how DocumentTemplate works in the context of Zope's Publishing Process.
Maybe I should study the Python source where this occurs. It's still VERY foggy! <g>
The source is the answer. what is the question? from DTMLMethod.py def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): """Render the document given a client object, REQUEST mapping, Response, and key word arguments.""" Cheers Kapil
-- Tim Cook -- FreePM Project Coordinator http://www.freepm.org OS Health Care Alliance Supporter http://www.oshca.org
Tim Cook wrote:
<dtml-in "objectValues(['DTML Document'])"> <dtml-if "doc_type == 'weekly'"> <dtml-call "done_list.append(week_begin.strftime('%Y / %m / %d'))"> </dtml-if> </dtml-in>
<dtml-call day_list>
Actually I guess it is more likely a problem in the done_list.append() changes not being visible to the dtml-in ??? -- Tim Cook -- FreePM Project Coordinator http://www.freepm.org OS Health Care Alliance Supporter http://www.oshca.org
participants (2)
-
Kapil Thangavelu -
Tim Cook