Datefields (problem with ZPsycopg and "/"s in dates)
[ 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.
Joel Burton wrote:
[ Tim -- Email to you bounces--might want to check your address. ]
Sorry about the email. I switch between several email clients through my day, and didn't realize Netscape's was not configured. Should be ok, now.
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?
All this works just fine. I haven't a clue in how to create a '.zexp', can you point me to the docs that say how to do this?
Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton Knowledge Management & Technology Consultant
(I've actually taken this off the zope@zope.org list since it's really unrelated to your question. We'll move it back on once we get back to the problem!)
All this works just fine. I haven't a clue in how to create a '.zexp', can you point me to the docs that say how to do this?
A .zexp is what you get when you export objects from Zope. . if the stuff relating to this problem isn't in a folder already, copy it into one . check the folder in the management interface listing and choose Export. This will put a file called "folder name.zexp" in your $ZOPE/var directory. Email it to me and I can see exactly what you're doing.
It suddenly dawned on me what the difference is between your python script and mine. This script works fine. But I would have thought that the "thedate" would be passed by dtml as a string. If that were the case then my version of your script would work: ndate = DateTime(thedate) m = ndate.Month() return "%s is the cruelest month" % m And indeed it does work when I run the test through the management screen. However, your example totally bypasses the DateTime() creation, assuming that thedate is already a DateTime() object whose methods only need to be accessed. This is evidence by the fact that your dtml works with your script, but fails in the test at the management screen. Pardon my ignorance in python, but can't you overload constructors in python? I am spoiled in this department by C++. it would be nice if DateTime(DateTime a) copied a DateTime object and DateTime(string b) created a new DateTime object. I just didn't know that dtml-sqlvar was already sending this database field as a datetime object, and I have no way of testing the script independent of the dtml, now.
# Pyscript "pyscript" # one parameter: "thedate"
m = thedate.Month() return "%s is the cruellest month" % m
I would still like info on zexp. I found an intro on Zope.org, but no other info. I like the concept.
participants (2)
-
Joel Burton -
Tim Hawes