[Zope] Datefields (problem with ZPsycopg and "/"s in dates)

Joel Burton joel@joelburton.com
Tue, 12 Mar 2002 14:26:42 -0500


[ Tim -- Email to you bounces--might want to check your address. ]



Not seeing the problem. Here's a small test case to make sure this isn't
a version difference between us. Can you see if this works?


# In psql:

CREATE TABLE datetest(id SERIAL PRIMARY KEY, thedate timestamp);
   [using date rather than timestamp works fine, too]

INSERT INTO datetest (thedate) VALUES ('2001-04-01');


# ZSQL Statement "select"
# no arguments or parameters

  SELECT id, thedate FROM datetest


# Pyscript "pyscript"
# one parameter: "thedate"

  m = thedate.Month()
  return "%s is the cruellest month" % m


# dtml method "dtml"

  <dtml-var standard_html_header>

  <dtml-in select>
    <dtml-var "pyscript(thedate)">
  </dtml-in>

  <dtml-var standard_html_footer>


View "dtml" and I get "April is the cruellest month"



If this works, can you send me a .zexp of your ZSQLMethod, Python Script,
and DTML Method, plus SQL DDL to create a table like yours?


Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant

> -----Original Message-----
> From: thawes@ncmail.net [mailto:thawes@ncmail.net]On Behalf Of Tim Hawes
> Sent: Tuesday, March 12, 2002 9:11 AM
> To: Joel Burton; zope@zope.org
> Subject: Re: [Zope] Datefields
>
>
> Joel Burton wrote:
>
> > On Mon, 11 Mar 2002, Tim Hawes wrote:
> >
> > > ZPsycoPG returns datefields from postgress in yyyy/mm/dd format, while
> > > postgres' default is yyyy-mm-dd. I need to pass a date to
> python script
> > > for comparison w/ other datefields, but Zope apparently will not allow
> > > values to be passed with '/'s in them. Can I change the way
> ZPsycoPG is
> > > returning the date fields in the database? How?
> >
> > Zope has no problem with passing a string like "2001/01/01" to a Python
> > Script. Why do you think that Zope will apparently not allow
> values to be
> > passed with "/" in them?
> >
> >
>
> Zope Error
>
>                          Zope has encountered an error while
> publishing this
> resource.
>
>                          Error Type: TypeError
>                          Error Value: unsupported operand type(s) for /
>
> Traceback (innermost last):
>   File /usr/local/zope/2.5.0/lib/python/ZPublisher/Publish.py,
> line 150, in
> publish_module
>   File /usr/local/zope/2.5.0/lib/python/ZPublisher/Publish.py,
> line 114, in
> publish
>   File /usr/local/zope/2.5.0/lib/python/Zope/__init__.py, line 158, in
> zpublisher_exception_hook
>     (Object: Projects)
>   File /usr/local/zope/2.5.0/lib/python/ZPublisher/Publish.py, line 98, in
> publish
>   File /usr/local/zope/2.5.0/lib/python/ZPublisher/mapply.py, line 88, in
> mapply
>     (Object: ChangeProject)
>   File /usr/local/zope/2.5.0/lib/python/ZPublisher/Publish.py, line 39, in
> call_object
>     (Object: ChangeProject)
>   File /usr/local/zope/2.5.0/lib/python/OFS/DTMLMethod.py, line 127, in
> __call__
>     (Object: ChangeProject)
>   File
> /usr/local/zope/2.5.0/lib/python/DocumentTemplate/DT_String.py, line
> 473, in __call__
>     (Object: ChangeProject)
>   File
> /usr/local/zope/2.5.0/lib/python/DocumentTemplate/DT_In.py, line 695,
> in renderwob
>     (Object: ProjectsUpdateResultMethod)
>   File
> /usr/local/zope/2.5.0/lib/python/DocumentTemplate/DT_Util.py, line 159,
> in eval
>     (Object: compare_datefield('start_',proj_start))
>     (Info: compare_datefield)
>   File <string>, line 2, in f
>   File
> /usr/local/zope/2.5.0/lib/python/Shared/DC/Scripts/Bindings.py, line
> 252, in __call__
>     (Object: compare_datefield)
>   File
> /usr/local/zope/2.5.0/lib/python/Shared/DC/Scripts/Bindings.py, line
> 283, in _bindAndExec
>     (Object: compare_datefield)
>   File
> /usr/local/zope/2.5.0/lib/python/Products/PythonScripts/PythonScri
> pt.py, line
> 291, in _exec
>     (Object: compare_datefield)
>     (Info: ({'script': <PythonScript instance at 1235610>, 'context': <r
> instance at 1383f28>, 'container': <Application instance at dd8220>,
> 'traverse_subpath': []}, ('start_', DateTime('2002/02/25')), {}, None))
>   File Script (Python), line 50, in compare_datefield
>   File Script (Python), line 12, in cdate
>   File /usr/local/zope/2.5.0/lib/python/DateTime/DateTime.py, line 668, in
> __init__
>   File /usr/local/zope/2.5.0/lib/python/DateTime/DateTime.py, line 276, in
> _calcSD
> TypeError: (see above)
>
>
> When I try to put this value in when I test the python script
> 'compare_date',
> it has no problems. I pass the value in dtml, I get this error.
> This is what
> has led me to believe that the problem is in how Zope handles it.
>
> Now, looking at it, perhaps the problem is in how I am calling it in dtml?
> Here is the dtml code that I use inside a database query sequence:
> <dtml-var expr="compare_datefield('start_',proj_start)">
> The first parameter is for an input tag variable name that is
> prepended to the
> default, the second (proj_start) is a dtml var containing a
> datefield for the
> script to compare. The end result is html code containing
> individual selection
> boxes for day, month and year, w/ the default selection at what
> is already in
> the database. I have another version of this script working that
> compares the
> DateTime() value with all date
> ranges to produce defaults for the current day, month, and year, and
> compare_date() does the same thing
> except that it creates a new DateTime() object from the second
> parameter that
> is passed to it.