[ZPT] Using alternatives to Zope's DateTime module in PageTemplates

charlie at egenix.com charlie at egenix.com
Thu Nov 16 17:58:12 EST 2006


Am 16.11.2006, 21:43 Uhr, schrieb Dieter Maurer <dieter at handshake.de>:

> 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=PythonScript('t')
>>>> ps.write('''##parameters=dt
> ... return dt.strftime('%d.%m.%Y')
> ... ''')
>>>> dt=datetime(2006,12,1,20,0,0)
>>>> ps.__of__(app)(dt)
> '01.12.2006'
> And this is the Python Script's code:
>
>>>> f=ps._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 method  
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


More information about the ZPT mailing list