Add annotations based on keywords (tutorial and code)

Maurits van Rees m.van.rees at zestsoftware.nl
Mon Jun 4 21:53:27 UTC 2007


Hi,

I have made a tutorial with some accompanying code that I would like
to point out to developers looking for example uses of zope 3 in
Plone.


I have a use case where I want to add annotations to a content type
when a specific keyword is added to it.  Specifically, I have one
normal Quills weblog here:

  http://maurits.vanrees.org/weblog

and a special Quills weblog with (links to) mp3 files for Dutch
sermons for my church:

  http://maurits.vanrees.org/preken

That last one is a normal Quills blog, but with zope 3 style
adaptations.  No Quills code was touched, except for one page template
which was copied.

I created a product for this and added it to the collective:

  https://svn.plone.org/svn/collective/keywordannotator/trunk

keywordannotator is the more generally useful part: add annotations to
content based on keywords.  The Quills specific part is in the
examples/quadapter (Quills Adapter) directory.  Both include tests.

I do not expect anyone else to actually use that quadapter product,
except as an example.  The keywordannotator product might be useful
though.  See the following partial test code:

    We give an object a non-special keyword and notify any event
    handlers that the object has been changed.

    >>> c.subject = 'blue'
    >>> notify(ObjectModifiedEvent(c))
    >>> IKeywordMatch.providedBy(c)
    False

    Now we try a keyword that is special.  This should have the effect
    that our object is marked with the IKeywordMatch interface.

    >>> c.subject = 'special'
    >>> notify(ObjectModifiedEvent(c))
    >>> IKeywordMatch.providedBy(c)
    True

So this product let's us use events and keywords (and an adaptable
utility) to conditionally add a marker interface (IKeywordMatch) to
objects.  That interface can be used to allow adding annotations to
that object.  For me, I used this to extend Quills weblog entries
marked with the 'audio' keyword and added two attributes with a link
to them.


keywordannotator and its example product quadapter have a tutorial in
the doc/ dir, which is also online here:

  http://maurits.vanrees.org/weblog/archive/2007/06/extend-with-zope-3

If you are looking for example uses of several zope 3 technologies, I
think this offers a nice read.


<salespitch>

I am not on http://planet.plone.org yet.  I have recently submitted a
request to be added to it:

https://dev.plone.org/plone.org/ticket/442

Hint, hint. ;)

Meanwhile, I will point to my atom feed for Plone:

http://maurits.vanrees.org/weblog/topics/plone/@@atom.xml

</salespitch>


-- 
Maurits van Rees | http://maurits.vanrees.org/ [NL]
            Work | http://zestsoftware.nl/
"Do not worry about your difficulties in computers,
 I can assure you mine are still greater."





More information about the Product-Developers mailing list