[Chandler-dev] Annotations 101

Alec Flett alecf at osafoundation.org
Fri Mar 17 13:11:35 PST 2006


> Perhaps I need to refresh my memory on how annotations work.   Do we 
> have the ability to index annotated attributes?
>
Here's annotations in 60 seconds:

Lets say your parcel 'fashion'  wants to remember what kind of pants to 
wear to each event:

class Outfit(schema.Annotation):
    schema.kindInfo(annotates=pim.CalendarEvent)
    pants = schema.One(schema.Text)

Now in the repository, all CalendarEvents have a persistent attribute 
called 'fashion.Outfit.pants' that is a string

You can either say
myPants = getattr(event, 'fashion.Outfit.pants')
or
myPants = Outfit(event).pants

to access the attribute. Outfit is merely a transitory object that 
'wraps' a CalendarEvent - the actual Outfit event exists for more 
readable/understandable code.

Since the attribute is like any other attribute, you can do anything you 
want - index, search, sort, whatever.

Annotations 102: The kind-tweaking in the schema happens to the actual 
Kind object, not to individual class instances, and only happens once 
the first time the class is actually declared.

Alec

> Ted
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
> Open Source Applications Foundation "chandler-dev" mailing list
> http://lists.osafoundation.org/mailman/listinfo/chandler-dev




More information about the chandler-dev mailing list