[z3-five] Annotations

Tim Hicks tim at sitefusion.co.uk
Wed Aug 18 00:20:46 MEST 2004


Martijn Faassen said:

>> I want to write an adapter for a class (an archetype in case that makes
>> any difference) that allows me to store and retrieve some additional
>> attributes that are not part of the basic schema.  I figure annotations
>> are a good way to go for this, right?
>>
>> If so, what would I need to do to use zope3 annotations in Five?
>>
>
> Hey,
>
> As Philipp wrote already, most of what is needed should be part of Zope
> 3. You might trip over things like new-style objects (Zope 3 might want
> to store a new style object), however.
>
> In any case, whether it is easy to make work or not, we'd appreciate
> very much a report if you get them working in Five, and even more a
> little writeup about how you did it. This way we can include a little
> recipe in the Five documentation, add some automatic tests perhaps, and
> include any code changes needed to Five in a future distribution.

Ok, I've been thinking about this some more...

I'll be a little more specific about things so as to aid explanation.  I'm
using Raphael Ritz's CMFBibliographyAT product from the collective, which
is a product for managing bibliographic references.  It's very good, but
it's dawned on me that from my personal point of view, the schema is a
little constrained.  For example, there is a schema for Books that has
fields for the title, the authors, the ISBN, etc, etc...

But, I've decided that what I want is to be able to see the front cover
image of a book when the details are displayed.  I've written a tool that
queries the Amazon site and fetches these details ('AmazonTool' in the
collective in case anyone is interested).  That's all very good, but it
doesn't seem right to add a field for storing this to the main book
schema... it's probably just me who cares about having the covers, and
even if it isn't, I'm sure I'll think of something nobody else wants soon
;-).  It is from this point that I started wondering about Five and
adapters...

... but I'm not quite sure how to integrate the working of adapters with a
plone/archetypes site.  The idea of adapters seems to be to change/add to
the behaviour of objects without touching them, but I don't know how to
expose this in my site without actually changing the objects (or their
class) themselves.

So, my (tentative) plan now for getting this working is something like:

1) Write a separate product that monkeypatches CMFBib book objects, adding
methods that provide access to the Amazon stuff that I want (and whatever
other out-of-scope attributes I fancy).

2) These monkeypatch methods will basically be a nice API for
setting/getting IAnnotation-stored details (as Philipp alluded in his
mail).

This seems workable, even if not quite in the zope3 spirit.  If anybody
can advise on a better way of doing this, then I'd love to hear about it.


My remaining problem is that I don't like writing HTML forms by hand, or
writing validators ;-).  I want my IAnnotation-stored attributes - forms
and validation - to be handled by a framework.  I'm used to relying on
Archetypes, but zope3's schema stuff sounds like a better fit here.

What problems (if any) do you foresee in exposing a zope3 schema-driven
form in a plone/archetypes object's 'tab'?  How would I expose such a form
(and it's validation) through the CMF/plone skins tool?


Slightly-confused-ly yours,

tim


More information about the z3-five mailing list