[Zope] on dates

Cliff Ford Cliff.Ford at ed.ac.uk
Mon Oct 11 14:45:43 EDT 2004


Just to be clear that we are on the same wavelength, do this:

Add a python script called test from the Add drop down list.

Type d in the Parameter List box

Put this and only this in the script textarea, replacing completely the 
default python script:

return DateTime(d).strftime('%H:%M, %a %d %b, %Y')

Save and test, typing 2004-10-11 in the Test Value box. It should give 
you the date. Now, in your page template make the call look like this:

<i tal:content="python: here.test(d='2004-10-11')"></i>

Test the page template. If that works, substitute the typed in date with 
the value that you are trying to display. If item.data is date string it 
should just work. If item.data is a more complex object then we are at 
cross purposes - but it should be because that us what MySQL stores.

Cliff

massimop at users.berlios.de wrote:
> On Mon, 2004-10-11 at 18:57 +0100, Cliff Ford wrote:
> 
>>You could try writing a wee Python script. This one gets the date from 
>>the query:
>>
>>for result in context.theQuery():
>>     print result.theDate.strftime('%H:%M, %a %d %b, %Y')
>>return printed
>>
>>Then call the script from the template.
>>
>>Alternatively, you could pass the date string to the Python script.
>>
>>Actually, I call a dtml object from a template, and the dtml calls the 
>>script (because the dtml has some extra HTML layout and the python does 
>>the date formatting - so the template looks uncomplicated).
>>
>>Cliff
>>
> 
> 
> following your suggestion (if I've understood) I tried this script:
> 
> ## Script (Python) "formatdate_py"
> ##bind container=container
> ##bind context=context
> ##bind namespace=
> ##bind script=script
> ##bind subpath=traverse_subpath
> ##parameters=d
> ##title=
> ##
> # Import a standard function, and get the HTML request and response
> objects.
> from Products.PythonScripts.standard import html_quote
> request = container.REQUEST
> RESPONSE =  request.RESPONSE
> 
> return d.day
> 
> 
> and then called it from a page template with:
> 
> <i tal:content="python: here.formatdate_py(item.data)"></i>
> 
> but it's sadly the same...
> 
> <<You are not allowed to access 'day' in this context>>
> 
> and it dosn't change if I pass 'item' to the script an access the field
> 'data' inside it
> 
> 
> thanks for your help
> massimo
> 
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope at 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 )


More information about the Zope mailing list