[Zope] Can't add "date" property to new ZClass
Loren Stafford
lstafford@icompression.com
Mon, 11 Oct 1999 16:18:23 -0700
After adding the report to the Collector, I went back to Zope to see what
would happen if I just put in a dummy value. It accepts it and goes on it's
merry way. So then I finish up the class, and modify the PDFClass_addForm
method to prompt for the class properties and the file ("File" is one of the
base classes). The date field looks like this: <input type=text
name="pub_date:date"> (You'd think ZClass could automatically put the
properties on the _addForm, too.)
Now it's time to try to create a test instance of the class. I get the
_addForm, fill in all the fields and submit. Success! ...well, almost.
There's a date in the new instance, but it's the dummy date I put in the
class, not the date I specified for the instance.
So I tried changing the form field to: <input type=text name="pub_date"> (no
type override) ...same result.
What's even weirder is that the method that displays objects with the "PDF
File" meta-type created by this class doesn't seem to get any date at all
from the object -- it shows up as empty -- neither the dummy class date nor
the instance date I put in.
Michel, is that what you meant by: "In fact, it should be smarter for
instances also"?
-- Loren
> From: Dr. Ross Lazarus [mailto:rossl@med.usyd.edu.au]
> Sent: Monday, October 11, 1999 15:11
> Subject: Re: [Zope] Can't add "date" property to new ZClass
>
> It's a mildly annoying "feature" - you need to put a default date -
> 2000/01/01 will work fine. Instances must be created with a date in that
> field. Sometimes I think it's easier to leave them as strings....same
> goes for int fields - must have a default.
Loren Stafford wrote:
>
> I'm creating a brand new ZClass (called "PDFClass"). It's my first ZClass.
> I've just added the Common Instance Property Sheet (called
"PDFProperties").
> Now I'm trying to add properties to that property sheet. I added one
> "string" property OK, but now when I add the "date" property "pub_date", I
> get this error:
>
> Zope Error
> Zope has encountered an error while publishing this resource.
> Invalid Date-Time String
> Sorry, a Zope error occurred.
>
> Traceback (innermost last):
> File /opt/Zope-2.0.0/lib/python/ZPublisher/Publish.py, line 214, in
> publish_module
> File /opt/Zope-2.0.0/lib/python/ZPublisher/Publish.py, line 179, in
> publish
> File /opt/Zope-2.0.0/lib/python/Zope/__init__.py, line 201, in
> zpublisher_exception_hook
> (Object: PDFProperties)
> File /opt/Zope-2.0.0/lib/python/ZPublisher/Publish.py, line 165, in
> publish
> File /opt/Zope-2.0.0/lib/python/ZPublisher/mapply.py, line 160, in
mapply
> (Object: manage_addProperty)
> File /opt/Zope-2.0.0/lib/python/ZPublisher/Publish.py, line 102, in
> call_object
> (Object: manage_addProperty)
> File /opt/Zope-2.0.0/lib/python/OFS/PropertySheets.py, line 403, in
> manage_addProperty
> (Object: PDFProperties)
> File /opt/Zope-2.0.0/lib/python/ZPublisher/Converters.py, line 157, in
> field2date
> File /opt/Zope-2.0.0/lib/python/DateTime/DateTime.py, line 499, in
> __init__
> Invalid Date-Time String: Sorry, an error occurred
>
> Of course, the value is invalid -- I didn't put any value in the "Value"
> box, because this is a class property, and values only make sense when the
> class is instantiated, right?
>
> Is this Zope's problem or mine?
Zope's. It should be a little smarter than that. In fact, it should be
smarter for instances also and just assume a sane value (like calling
DateTime() with no arguments, which returns 'now').
Please submit to the Collector. Should be a pretty trivial fix if you
want to take a hack at it and submit a patch, just sniff for a null
value and insert DateTime() instead of DateTime(formvalue).
-Michel