Can't add "date" property to new ZClass
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? -- Thanks -- Loren
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
On Mon, 11 Oct 1999 15:06:50 -0700, you 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:
Invalid Date-Time String
Are you planning to extract properties from PDF files? That's a task on my to-do list too.
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?
This is a detail carried over from Python, where class attributes can be used as default values for 'missing' instance attributes. This is useful (once you know how it works ;-) if you have created some instances before making a change to a class. The instances automatically get the new attribute with the default value, and this happens without any database transactions since their instance attributes have not changed. Hope this helps, Toby Dickenson
I'm creating a brand new ZClass (called "PDFClass"). It's my first ZClass.
Are you planning to extract properties from PDF files? That's a task on my to-do list too.
That's on my long-range plan. I once wrote the code to do that in Perl (tho it may have been left behind at at former employer). I'm not anxious to do it again in Python. There must be some C libraries somewhere (perhaps even from Adobe) that do the job and can be wrapped in Python. Then there's another technical detail I haven't even thought about yet: How do you programmatically rummage around inside the PDF file, parsing the PDF structure, when the PDF file is already a Zope object in ZODB? I have confidence that that will be easy; I just have no clue how. But for right now I just want to get familiar with Z Classes for use in another project. A "dumb" PDF class seemed like a good learning project.
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?
This is a detail carried over from Python, where class attributes can be used as default values for 'missing' instance attributes.
This is useful (once you know how it works ;-) if you have created some instances before making a change to a class. The instances automatically get the new attribute with the default value, and this happens without any database transactions since their instance attributes have not changed.
Thanks for confirming what I was beginning to suspect. I'm writing up some of my experiences with Z Classes in a How-To at http://www.zope.org/Members/lstaffor/zProperties where I imply that you can use Property Sheets for all possible variations of class and instance attributes, depending on how you use Zope's and custom methods on the properties. But I haven't had the time yet to experiment with more than a few variations. Maybe you would like to take a look and make sure I'm on the right track. I quess there are three variations: 1. You want a class attribute to be inherited by an instance and retain the class value. This is the behavior you just described. 2. You don't want to inherit the value of an instance attribute from the class (as for the publication date of the document). It doesn't really matter what value you put in the class attribute, because you are going to override it later. But, Zope forces you to put some value in the attribute anyway when you create the class. This is a nuisance. You might think to put in a null value. But what is a null value for type "date"? (A rhetorical question. 8-) 3. You want the value of the class attribute to be the default value for the instance attribute but allow override at the time the instance is created. How do you get the class value into the PDFClass_addForm? The class attributes don't seem to be in the namespace at that point (or are they in some other namespace I don't know about?). -- Thanks -- Loren
participants (3)
-
Loren Stafford -
Michel Pelletier -
Toby Dickenson