N Burnett wrote:
I have been trying for a while to get arguments passed to a ZSQL Method from inside a dtml-in loop. My top level objective is to update a table with multiple changes to date/times and descriptions in records about conference sessions input from a form. Having read many posts here and other documentation, my current attempt should work, but I can't get it right yet. I keep getting a TypeError in the DateTime function indicating that the date isn't being passed in the format I think it should be:
Here is the dtml I am trying:
(The relevant fields in the table are: ID,StartsAt,aDescription)
<dtml-var standard_html_header> <dtml-if expr="REQUEST.has_key('submit')"> <dtml-in s> <dtml-call expr="sessions_modifydates(_)"> </dtml-in> </dtml-if>
assuming "s" is some kind of a state variable there should be a <input type="hidden" name="s" value="1"> in the form below (note the double quotes)
<form method=post action=sessions_update> <table> <dtml-in sessions_list> <tr><td> <input type=text name=s.ID:records value=<dtml-var ID> size=4>
tried? <input type="text" name="s.ID:records:int" value="<dtml-var ID>" size=4>
</td><td> <input type=text name=s.StartsAt:records:date value="<dtml-var StartsAt>"> </td><td> <input type=text name=s.aDescription:records value="<dtml-var aDescription>" size=60>
again <input type="text" name="s.aDescription:records:text" value="<dtml-var aDescription>" size=60> if the type is not 'text', something else?
</td><tr> </dtml-in> </table>
<input type="hidden" name="submit" value="1">
<input type=submit name=submit> </form> <dtml-var standard_html_footer>
The (not very well named) ZSQL Method sessions_modifydates is as follows. If it gets a date that DateTime can recognize, it converts it to SQL format:
has your zsql method parameter declarations? with types? like StartsAt:date aDescription:text ID:int
UPDATE tblSession SET tblSession.StartsAt = <dtml-var expr="_.DateTime(StartsAt).strftime('#%m/%d/%Y %H:%M:%S#')">, tblSession.Description = <dtml-sqlvar aDescription type=string> <dtml-sqlgroup where> <dtml-sqltest ID op=eq type=int> <dtml-and> <dtml-sqltest ConferenceID op=eq type=int> </dtml-sqlgroup>
(Note that commenting out the updating of the date then allows the description to be updated, so I think everything else works OK. I use 'aDescription' because I thought Description may have been a reserved word somewhere along the line, but it probably isn't.)
For completeness, here is the traceback I get:
Traceback (innermost last): File C:\Programmer\WebSite\lib\python\ZPublisher\Publish.py, line 150, in publish_module File C:\Programmer\WebSite\lib\python\ZPublisher\Publish.py, line 114, in publish File C:\Programmer\WebSite\lib\python\Zope\__init__.py, line 158, in zpublisher_exception_hook (Object: sss)
where does "sss" come from?
File C:\Programmer\WebSite\lib\python\ZPublisher\Publish.py, line 98, in publish File C:\Programmer\WebSite\lib\python\ZPublisher\mapply.py, line 88, in mapply (Object: sessions_update) File C:\Programmer\WebSite\lib\python\ZPublisher\Publish.py, line 39, in call_object (Object: sessions_update) File C:\Programmer\WebSite\lib\python\OFS\DTMLMethod.py, line 127, in __call__ (Object: sessions_update) File C:\Programmer\WebSite\lib\python\DocumentTemplate\DT_String.py, line 473, in __call__ (Object: sessions_update) File C:\Programmer\WebSite\lib\python\DocumentTemplate\DT_In.py,
line 695, in renderwob (Object: s) File C:\Programmer\WebSite\lib\python\DocumentTemplate\DT_Util.py,
line 159, in eval (Object: sessions_modifydates(StartsAt=_['sequence-var- StartsAt'])) (Info: _) File <string>, line 2, in f File C:\Programmer\WebSite\lib\python\Shared\DC\ZRDB\DA.py, line 414, in __call__ (Object: sessions_modifydates) File C:\Programmer\WebSite\lib\python\DocumentTemplate\DT_String.py, line 473, in __call__ (Object: <string>) File C:\Programmer\WebSite\lib\python\DocumentTemplate\DT_Util.py,
line 159, in eval (Object: _.DateTime(StartsAt).strftime('#%m/%d/%Y %H:%M:%S#')) (Info: StartsAt) File <string>, line 2, in f File C:\Programmer\WebSite\lib\python\DateTime\DateTime.py, line 671, in __init__ File C:\Programmer\WebSite\lib\python\DateTime\DateTime.py, line 279, in _calcSD TypeError: (see above)
this is the culprit: Your DateTime argument StartsAt is malformed in some way. Looking into lib\python\DateTime\DateTime.py, shows, that if the argument do DateTime() is of type string, DateTime tries to convert string using a method "_calcSD", its def beeing at line 272 like def _calcSD(t): # Returns timezone-independent days since epoch and the fractional # part of the days. dd = t + EPOCH - 86400.0 d = dd / 86400.0 s = d - math.floor(d) return s, d hans -- ------------------------------------------------------------- Who's got only a hammer sees the world as a nail hans augustin (software developer) hans@beehive.de beehive elektronische medien GmbH http://www.beehive.de phone: +49 30 847-82 0 fax: +49 30 847-82 299