[ZPT] Select/Repeat Syntax
Tino Wildenhain
tino at wildenhain.de
Tue Aug 3 06:03:53 EDT 2004
Hi Philip,
Am Di, den 03.08.2004 schrieb Philip Kilner um 6:45:
> Hi Andreas,
> ...
> I now have: -
>
> <select name="Assessdate"
> tal:define="AssessList here/rsOpenAssessments">
> <option tal:repeat="Assess AssessList"
> tal:attributes="value Assess/ExaminationDate;
> SELECTED python:
> result.CurrentDate==Assess.ExaminationDate"
> tal:content="python:
> Assess.ExaminationDate.strftime('%d/%m/%Y')">ExaminationDate</option>
> </select>
>
> FWIW, I'm currently wrestling with: -
>
> <span tal:replace="python:
> result.CurrentDate.strftime('%d/%m/%Y')">Date</span>
>
> ...which fails (on strftime) when CurrentDate is null - but I can't for
> the life of me figure out how to make the evaluation dependant upon the
> date being populated.
If you want a lot of transformations, just do these in a small python
script. This keeps your ZPT free of complicated expressions, make
it more easy to maintain (scroll down a complex template to find
the occurence and compare it with a 5-10 liner python script),
allows for more sophisticated transformations and last not least
gives you the posibility to access your data via XMLRPC for free :-)
For the above for example, I'd use:
return [{'ExaminationDate':ass.ExaminationDate,
'CurrentDate':(ass.CurrentDate and
result.CurrentDate.strftime('%d/%m/%Y')) or '',
'selected':result.CurrentDate == ass.ExaminationDate}
for ass in context.rsOpenAssessments]
wherever you get this 'result' from. I expect another ZSQL method?
If so you should rather use a left outer join in the DB.
Instead of just a list, the python script can return a whole
structure to use in your template, call your template (instead
of beeing called within the template) and so on.
Regards
Tino Wildenhain
More information about the ZPT
mailing list