[Zope3-Users] making anything taggable
Maken Seteva
crapkonto at gmail.com
Fri Sep 14 06:05:21 EDT 2007
Hi!
Opening up a new thread since the old one is using some old ideas,
but still thanks to Douglas for replying :)
What I'm really trying to do is probably analogous to the buzzword
"tagging". In other words a component can have
a list of keywords that describe it. I saw Jeff's sketchy solution in
another thread but he basically used dublincore..
I want to implement it with my own annotations. Here's my idea:
------------
class ITaggable(IAnnotatable):
"""Marker interface for components that can be tagged"""
class ITagging(Interface):
tags = List(Word())
-------------
KEY = "foo.bar"
class Tagging(object):
implements(ITagging)
adapts(ITaggable)
def __init__(self, context):
self.context = self.__parent__ = context
tags = IAnnotations(context).get(KEY)
if tags is None:
tags = annotations[KEY] = PersistentList()
self.tags = tags
--------------
<adapter
factory=".tagging.Tagging"
trusted="true"
locate="true"
/>
<class class=".tagging.Tagging">
<require
permission="zope.View"
interface=".interfaces.ITagging"
/>
</class>
-----------
Any class that wants to be taggable needs to have ITaggable in its
<implements interface="..."/>. And then i simply
add Fields(ITagging) to the form_fields of the Add and Edit form.
This doesn't work, tags doesn't get written
and I think something is missing in the Tagging implementation
because how would the add/edit-forms know how
to write to the tags attribute?
btw, here's my implementation of the Word schema field i wrote:
class Word(TextLine):
"""A word cannot contain spaces"""
def constraint(self, value):
return super(Word, self).constraint(value) and ' ' not in
value
Thanks!
Setava
More information about the Zope3-users
mailing list