简单的标记适配器
项目描述
largeblue.tag提供了一种超简单的标记适配器。如果包含
<include package="largeblue.tag" />
它将适配任何配置为实现largeblue.tag.interfaces.ITaggable的对象,例如
<class class=".objects.MyContentObject"> <implements interface="largeblue.tag.interfaces.ITaggable" /> ... </class>
这将为适配的内容对象的每个实例挂起一个@@tags.html视图,该视图提供单行文本输入以输入标签(由空格分隔)。因此,如果您在文本输入中输入“foo bar dolores”并提交,您将找到
>>> context = my_obj >>> from largeblue.tag.interfaces import ITag >>> t = ITag(context) >>> t.tags ['foo', 'bar', 'dolores'] >>> t.tagstring u'foo bar dolores'
您可以添加、删除和更新
>>> t.add_tag('elephants') >>> t.tags ['foo', 'bar', 'dolores', 'elephants'] >>> t.remove_tag('dolores') >>> t.tags ['foo', 'bar', 'elephants'] >>> t.update_tags(['coffee', 'milk']) >>> t.tags ['coffee', 'milk']
就这么多。