[Zope] Using Zclasses
Alexander Staubo
alex@mop.no
Tue, 6 Jul 1999 04:28:17 +0200
>Alexander Staubo wrote:
>>
>> To answer your first question, let your "parent" ZClass be a
>descendant
>> of Object Manager; then define your "child" ZClass _within_
>the parent
>> ZClass definition; that is, add the child ZClass as a
>subobject of the
>> parent.
>
>I assume that you mean that I should create the 'child' ZClass within
>the 'Methods' tab of the parent?
Yes, that's how it's supposed to work, odd as it may seem. Never tried
this myself, though.
>> Your second question is trickier, because Zope does not,
>afaik, support
>> properties that are objects. It's possible, but I believe
>you can't edit
>> these properties through the standard management interfaces. Instead,
>> you must built your own, and you might have to use Python to
>store these
>> properties.
>
>Hmm, seems a pretty important feature, does anyone know if this sort of
>functionality is on the drawing board for the Zope interface?
Post it to the Collector (http://www.zope.org/Collector) if you think
it's important. I agree; but this prompt the question: "Yes, but how?"
Should you be able to define properties that can accept only one type of
object? Several types? Any type of object? Another aspect is
interdependencies -- you might want to introduce deletion constraint on
which objects may be deleted if they're referenced, and so on.
>> The alternative, of course, is to use a string property and
>refer to the
>> object's ID. Acquisition will permit you to access any object in the
>> hierarchy above the object in question.
>
>Do you have an example of a simple working application that uses this
>technique?
Nope, but assuming that document Foo has a string property OtherObject,
you can do this(untested)::
Other object's id is: <!--#var "_[OtherObject].id()"-->
Title of that object is: <!--#var
"_[OtherObject].title_or_id()"--><br>
Result of osme method call: <!--#var
"_[OtherObject].GetSomething(this())"--><br>
>And what happens when the pointed-to object is deleted or
>modified?
Nothing, so you should do something like this in the documents that use
the contents of the property::
<!--#if "not HasAttr(PARENTS[0], OtherObject)"-->
<!--#call "manage_changeProperties({'OtherObject': ''})"-->
<!--#/if-->
or something like that, assuming HasAttr() is an External Method that
tests for the existence of a property (I have not found this
functionality in Zope's built-in DTML API: The closest I you get is
getattr, which raises an error if it fails). I implement this function
like so::
def HasAttr(o, attr):
return hasattr(o, attr)
--
Alexander Staubo http://www.mop.no/~alex/
"What the hell, he thought, you're only young once, and threw
himself out of the window. That would at least keep the element of
surprise on his side."
--Douglas Adams, _The Hitchhiker's Guide to the Galaxy_