简单标记适配器
largeblue.tag的Python项目详细描述
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']
就这样。