[ZPT] Formatting dates with ZPT
Petter Enholm
Petter Enholm" <pe@snapper.no
Fri, 22 Mar 2002 08:00:03 +0100
Hi,
First: This is a matter of personal taste. I think that one of the most
important aspects with the ZPT is that you can pursue a clean three tier
model. Hence I always try to keep the templates as clean as possible,
removing any logic connected to sql, differences in display etc. I call
database/SQL - methods in separate Python scripts, so that I easily can
create new templates for f ex AvantGO or other platforms.
I often define a date format for a web site and create a Python script the
renderes the date in that format. Then it is easy to reformat the date
string without going through all the templates.
Other times I create a tiny script the "hides" the DateTime routine, which
you can also call directly from ZTP using modules ... refer to the ZPT docs
for this.
Anyway here are some examples of how I do it (hand coded into mailprogram,
not tested as is):
def renderPublishDate(date):
import DateTime
return DateTime.DateTime(int(date)).strftime('%d.%m.%Y %H:%M')
or
def formatDate(date, format):
import DateTime
return DateTime.DateTime(int(date)).strftime(format)
Hope this can help you, and like I said. It is a matter of personal taste
how you construct your scripts and order the different render og logical
elements....
Best regards
Petter Enholm
----- Original Message -----
From: "Luis Lavena" <luislavena@hotmail.com>
To: <zpt@zope.org>
Sent: Friday, March 22, 2002 7:22 AM
Subject: [ZPT] Formatting dates with ZPT
> I'm dealing with format a ZSQLMethod resultset in a table on a
pagetemplate.
>
> Because I get a bunch of dates jsut for one row, need a way like dtml that
> you use dtml-var with the fmt attribute.
>
> Is there a comparable or similar way to achieve this without calling for
> each field a pythonscript?
>
> Thanks in advance for the answers,
>
> Luis
>
> _______________________________________________
> ZPT mailing list
> ZPT@zope.org
> http://lists.zope.org/mailman/listinfo/zpt
>