[Zope] Can't add "date" property to new ZClass

Loren Stafford lstafford@icompression.com
Wed, 13 Oct 1999 11:25:37 -0700


>
> >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