Re: Using alternatives to Zope's DateTime module in PageTemplates

"[email protected]" <[email protected]> Thu, 16 Nov 2006 23:58:12 +0100
Newsgroups gmane.comp.web.zope.page-templates
Organization eGenix.com
Message-ID <[email protected]>
Am 16.11.2006, 21:43 Uhr, schrieb Dieter Maurer <[email protected]>:

> I am not surprised that you are formatting a database result.
> I am surprised that in the byte code there is an "import time"
> (or an import at all).
> I tried to reproduce your problem and failed:
> bin/zopectl debug
>>>> from datetime import datetime
>>>> from AccessControl import allow_type
>>>> allow_type(datetime)
>>>> from Products.PythonScripts.PythonScript import PythonScript
>>>> ps=3DPythonScript('t')
>>>> ps.write('''##parameters=3Ddt
> ... return dt.strftime('%d.%m.%Y')
> ... ''')
>>>> dt=3Ddatetime(2006,12,1,20,0,0)
>>>> ps.__of__(app)(dt)
> '01.12.2006'
> And this is the Python Script's code:
>
>>>> f=3Dps._v_f
>>>> from dis import dis
>>>> dis(f.func_code)
>   1           0 LOAD_GLOBAL              0 (_getattr_)
>               3 LOAD_FAST                0 (dt)
>               6 LOAD_CONST               1 ('strftime')
>               9 CALL_FUNCTION            2
>              12 LOAD_CONST               2 ('%d.%m.%Y')
>              15 CALL_FUNCTION            1
>              18 RETURN_VALUE
>              19 LOAD_CONST               0 (None)
>              22 RETURN_VALUE
> I am using Zope 2.8.1 with Python 2.4.1.

Interesting - in my script there is actually no import just a formatting=
  =

statement for something that is subsequently passed to an external metho=
d  =

to generate a PDF but is the same error I get when using datetime types.=
  =

The interesting thing is that allow_type explicitly says that extension =
 =

types like datetime will not work. I have used "allow_type" in a generic=
  =

"Tools" script so that I can use in scripts or PageTemplates (which is  =

where it should be allowed to be used). I will give your script a go and=
  =

see how that works.

Thanks very much for your help and your profound understanding of the  =

internals of Zope.

Charlie