[Zope] (no subject)
Joel Burton
joel@joelburton.com
Thu, 28 Feb 2002 11:01:47 -0500 (EST)
On Thu, 28 Feb 2002, jkinsley wrote:
> How can I add a subobject to a container where the subobject id
> is the same as a container property so that the subobject will be
> used instead of the the container property? Is this a good idea,
> and/or is there a better way?
>
>
> class Container(...ObjectManager, PropertyManager...)
> """A Folderish Object Product
> """
>
> ...
>
> _properties = (
> {'id:'title', 'type':'string', 'mode':'w'},
> {'id:'default', 'type':'string', 'mode':'w'},
> )
>
> ...
>
> __init__(self, id, title='', default=''):
> self.id=id
> self.title=title
> self.default=default
>
> ...
>
> Now in Zope I add a 'Container' object with id ZContainer and set
> ZContainer.default = 'The default value.' In most instances this
> is sufficient, but on occassion is is necessary to get the value of
> content from a more complex object such as a Document. In such a
> case I would like to be able to simply add a Document object to
> ZContainer with 'default' as its id so that when ZContainer.default
> is called, the contents of the Document are returned instead of the
> value of the default property. If this is not a good idea, what are
> the alternatives?
So, right now, ZContainer returns the ZContainer.default rather than the
ZContainer.objectValues()['default'] ?
How about:
* tweaking with the __of__ acquisition method for ZContainer to mangle
requests for default to look in the right place (I'd be on slightly shaky
ground about exactly how to code this, but I think it's a workable idea,
and if so, would require no code change. Of course, it might have nasty
side effects on attempts to set/delete the default property, mangling
those to the default contained-object. Perhaps these could be routed
around. Not sure.)
* more simply, write a getDefault() property in ZContainer and calling
that instead. This would do the checking and return the right thing.
--
Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton
Independent Knowledge Management Consultant