[Dev] mapping python back to the repository
vajda at osafoundation.org
Tue Feb 15 10:39:38 PST 2005
> Right now, we have a way of mapping a repository kind back to a python
> class - you just say <classes ...>*python class*</classes>
> The problem I'm running into now is that I want to create an instance of
> a python class and an entry in the repository, but I'm not really sure
> what the proper way is. Specifically, I want to create an ItemCollection,
> but when I say
> c = ItemCollection()
When creating an item instance (or a subclass thereof) you need to pass three
- a name, which is optional and is useful for debugging
- a parent, which determines where the item lives in the repository
- a kind, which is optional. A kindless item is limited in what it can do
but is useful as a container of other items, its children (see above).
The class of the item instance used is the class you just used to invoke the
constructore as in ItemCollection(), but you can also instantiate item via
Kind.newItem() passing it the same arguments plus maybe a class. If no class
is passed in then the class the kind knows about is used.
If the ItemCollection constructor takes no arguments and doesn't propagate up
to Item, of which it must be a subclass (not necessarily a direct one of
course), then that's two bugs right there. The Item constructor requires name,
parent and kind, but name and kind can be None.
The repository parent/child hierarchy is something we're using for schema and
for debugging, but we've decided from the beginning to not put any meaning
into it. Therefore, most Chandler content item classes have some logic for
defaulting what these arguments are. I also added more defaulting features
recently, defaultParent and defaultKind, which Morgen said he'd hook into the
content model classes to make this even simpler.
More information about the Dev