ZopeTime() in python script ...
Hi! I have a messy dtml block that returns a yyyymmdd date string using zope time: # <dtml-var "(ZopeTime()).year()" # ><dtml-if # expr="(ZopeTime()).month()<10" # >0<dtml-var "(ZopeTime()).month()" # ><dtml-else # ><dtml-var "(ZopeTime()).month()" # ></dtml-if # ><dtml-if # expr="(ZopeTime()).day()<10" # >0<dtml-var "(ZopeTime()).day()" # ><dtml-else # ><dtml-var "(ZopeTime()).day()" # ></dtml-if> This works, BUT I would like to forget the dtml and just write it in python. Something like this?: # str="" # str = str + ZopeTime().year() # if ZopeTime().month()<10: # str = str + "0" # str = str + ZopeTime().month() # if ZopeTime().month()<10: # str = str + "0" # str = str + ZopeTime().day() # return str But this gives an error: Error Type: NameError Error Value: ZopeTime I have this as a python script object and although it would return a string ok, I get an error when trying to access ZopeTime(). I am currently losing my mind trying different arguments and import statements, but getting nowhere fast. How do I access the variables and methods (those that would normally be available to a dtml method) in a python script? thanks, mike -- [morcilla@ketden.com chikoon]$ whoami Mike Blake
On Thu, May 10, 2001 at 01:56:17PM +0200, Mike Blake wrote:
This works, BUT I would like to forget the dtml and just write it in python. Something like this?:
# str="" # str = str + ZopeTime().year() # if ZopeTime().month()<10: # str = str + "0" # str = str + ZopeTime().month() # if ZopeTime().month()<10: # str = str + "0" # str = str + ZopeTime().day() # return str
But this gives an error: Error Type: NameError Error Value: ZopeTime
I have this as a python script object and although it would return a string ok, I get an error when trying to access ZopeTime().
I am currently losing my mind trying different arguments and import statements, but getting nowhere fast. How do I access the variables and methods (those that would normally be available to a dtml method) in a python script?
thanks, mike
-- [morcilla@ketden.com chikoon]$ whoami Mike Blake
You can access objects available under dtml by using "context" or "container". So something like: context.ZopeTime() should work. ------------------------------------------------------ Andres Corrada-Emmanuel Email: andres@corrada.com Internet Programming http://www.mamey.com ------------------------------------------------------
DTML <dtml-var ZopeTime> == <dtml-var "ZopeTime()"> Python Script timeobject = context.ZopeTime() day = timeobject.strftime('%A') Hope this helps! peter ----- Original Message ----- From: "Mike Blake" <mike.blake@cellnetwork.com> To: <zope@zope.org> Sent: Thursday, May 10, 2001 1:56 PM Subject: [Zope] ZopeTime() in python script ...
Hi!
I have a messy dtml block that returns a yyyymmdd date string using zope time:
# <dtml-var "(ZopeTime()).year()" # ><dtml-if # expr="(ZopeTime()).month()<10" # >0<dtml-var "(ZopeTime()).month()" # ><dtml-else # ><dtml-var "(ZopeTime()).month()" # ></dtml-if # ><dtml-if # expr="(ZopeTime()).day()<10" # >0<dtml-var "(ZopeTime()).day()" # ><dtml-else # ><dtml-var "(ZopeTime()).day()" # ></dtml-if>
This works, BUT I would like to forget the dtml and just write it in python. Something like this?:
# str="" # str = str + ZopeTime().year() # if ZopeTime().month()<10: # str = str + "0" # str = str + ZopeTime().month() # if ZopeTime().month()<10: # str = str + "0" # str = str + ZopeTime().day() # return str
But this gives an error: Error Type: NameError Error Value: ZopeTime
I have this as a python script object and although it would return a string ok, I get an error when trying to access ZopeTime().
I am currently losing my mind trying different arguments and import statements, but getting nowhere fast. How do I access the variables and methods (those that would normally be available to a dtml method) in a python script?
thanks, mike
-- [morcilla@ketden.com chikoon]$ whoami Mike Blake
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Mike Blake wrote:
I have a messy dtml block that returns a yyyymmdd date string using zope time:
# <dtml-var "(ZopeTime()).year()" # ><dtml-if # expr="(ZopeTime()).month()<10" # >0<dtml-var "(ZopeTime()).month()" # ><dtml-else # ><dtml-var "(ZopeTime()).month()" # ></dtml-if # ><dtml-if # expr="(ZopeTime()).day()<10" # >0<dtml-var "(ZopeTime()).day()" # ><dtml-else # ><dtml-var "(ZopeTime()).day()" # ></dtml-if>
Yurg! :-S What's wrong with: <dtml-var ZopeTime fmt="%Y%m%d"> ?!? Chris
participants (4)
-
andresï¼ corrada.com -
Chris Withers -
Mike Blake -
Peter Bengtsson