Python2.3 datetime VS Zope DateTime
I'm now trying to publish a set of database-related logics through zope. Some of them return a python2.3's datetime object which its member access are disallowed from zope. (DTML, ZPT) I want to access some of datetime's member-methods, like strftime & isocalendar. How can I make it accessible from zope ? Or how can I make Zope automagically convert it to Zope's DateTime. I really don't want to change my logics to use Zope's DateTime. Thanks.
From: "Sakesun Roykiattisak" <sakesun@boonthavorn.com>
I'm now trying to publish a set of database-related logics through zope. Some of them return a python2.3's datetime object which its member access are disallowed from zope. (DTML, ZPT) I want to access some of datetime's member-methods, like strftime & isocalendar. How can I make it accessible from zope ? Or how can I make Zope automagically convert it to Zope's DateTime. I really don't want to change my logics to use Zope's DateTime.
DateTime and strftime are accessible from dtml: <dtml-let e="_.DateTime()"> strftime(%Y/%m/%d) --> <dtml-var expr="e.strftime('%Y/%m/%d')"> </dtml-let> Jonathan
In fact, I mean python2.3's datetime.datetime. However, with your hint, I've found I can do this. <dtml-let d="getInvoiceDate('INV10001')"> <dtml-var "_.DateTime(str(d)).strftime('%d/%m/%Y')"> </dtml-let> or in ZPT <span tal:omit-tag="" tal:define="d python:here.getInvoiceDate('INV10001')"> <span tal:replace="python:DateTime(str(d)).strftime('%d/%m/%y)"/> </span> Ther are pretty verbose. But it works anyway. Thank you very much for your tip. Small Business Services wrote:
From: "Sakesun Roykiattisak" <sakesun@boonthavorn.com>
I'm now trying to publish a set of database-related logics through zope. Some of them return a python2.3's datetime object which its member access are disallowed from zope. (DTML, ZPT) I want to access some of datetime's member-methods, like strftime & isocalendar. How can I make it accessible from zope ? Or how can I make Zope automagically convert it to Zope's DateTime. I really don't want to change my logics to use Zope's DateTime.
DateTime and strftime are accessible from dtml:
<dtml-let e="_.DateTime()"> strftime(%Y/%m/%d) --> <dtml-var expr="e.strftime('%Y/%m/%d')"> </dtml-let>
Jonathan
I had the same problem before: http://marc.theaimsgroup.com/?l=zope&m=107784430723371&w=2 I was suggested to use Zope's DateTime, however I don't want to use Zope specific stuff where there's a python alternative. I created a small wrapper around the datetime object: class dtwrap(datetime): __allow_access_to_unprotected_subobjects__ = 1 Wherever I'd pass a datetime 'D' to a zpt, I pass getdwrapper(D) instead, where getdwrapper is: def getdwrapper(d): return dtwrap(d.year, d.month, d.day, d.hour, d.minute, d.second, d.microsecond) Anyway, it would be nice if zpt could handle the native python datetime. Regards, Sandor
-----Original Message----- From: zope-bounces+zope=netchan.cotse.net@zope.org [mailto:zope-bounces+zope=netchan.cotse.net@zope.org] On Behalf Of Sakesun Roykiattisak Sent: Friday, March 26, 2004 6:44 AM To: Small Business Services Cc: zope@zope.org Subject: Re: [Zope] Python2.3 datetime VS Zope DateTime
In fact, I mean python2.3's datetime.datetime. However, with your hint, I've found I can do this.
<dtml-let d="getInvoiceDate('INV10001')"> <dtml-var "_.DateTime(str(d)).strftime('%d/%m/%Y')"> </dtml-let>
or in ZPT
<span tal:omit-tag="" tal:define="d python:here.getInvoiceDate('INV10001')"> <span tal:replace="python:DateTime(str(d)).strftime('%d/%m/%y)"/> </span>
Ther are pretty verbose. But it works anyway.
Thank you very much for your tip.
Small Business Services wrote:
From: "Sakesun Roykiattisak" <sakesun@boonthavorn.com>
I'm now trying to publish a set of database-related logics through zope. Some of them return a python2.3's datetime object which its member access are disallowed from zope. (DTML, ZPT) I want to access some of datetime's member-methods, like strftime & isocalendar. How can I make it accessible from zope ? Or how can I make Zope automagically convert it to Zope's DateTime. I really don't want to change my logics to use Zope's DateTime.
DateTime and strftime are accessible from dtml:
<dtml-let e="_.DateTime()"> strftime(%Y/%m/%d) --> <dtml-var expr="e.strftime('%Y/%m/%d')"> </dtml-let>
Jonathan
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
"__allow_access_to_unprotected_subobjects__" Yucks ! I've just discovered "management_page_charset" last 2 weeks. My life with Zope would be much simple if I had aware of its existence from the beginning. It's really annoying that there are no systematically way, AFAIK, to look for information on these obscure tricks.(besides source code and mailing list, of course) Thank you, anyway. zope@netchan.cotse.net wrote:
I had the same problem before: http://marc.theaimsgroup.com/?l=zope&m=107784430723371&w=2 I was suggested to use Zope's DateTime, however I don't want to use Zope specific stuff where there's a python alternative.
I created a small wrapper around the datetime object:
class dtwrap(datetime): __allow_access_to_unprotected_subobjects__ = 1
Wherever I'd pass a datetime 'D' to a zpt, I pass getdwrapper(D) instead, where getdwrapper is:
def getdwrapper(d): return dtwrap(d.year, d.month, d.day, d.hour, d.minute, d.second, d.microsecond)
Anyway, it would be nice if zpt could handle the native python datetime.
Regards, Sandor
participants (3)
-
Sakesun Roykiattisak -
Small Business Services -
zope@netchan.cotse.net