[Checkins] SVN: lovely.tag/trunk/src/lovely/tag/ implemented rename method in engine

Bernd Dorn bernd.dorn at lovelysystems.com
Mon Jan 8 08:29:42 EST 2007


Log message for revision 71804:
  implemented rename method in engine

Changed:
  U   lovely.tag/trunk/src/lovely/tag/README.txt
  U   lovely.tag/trunk/src/lovely/tag/configure.zcml
  U   lovely.tag/trunk/src/lovely/tag/engine.py
  U   lovely.tag/trunk/src/lovely/tag/interfaces.py

-=-
Modified: lovely.tag/trunk/src/lovely/tag/README.txt
===================================================================
--- lovely.tag/trunk/src/lovely/tag/README.txt	2007-01-08 13:29:07 UTC (rev 71803)
+++ lovely.tag/trunk/src/lovely/tag/README.txt	2007-01-08 13:29:41 UTC (rev 71804)
@@ -558,7 +558,7 @@
 Let us add our image object again.
 
   >>> tagging = tag.interfaces.ITagging(image)
-  >>> tagging.update(u'srichter', u'newtag')
+  >>> tagging.update(u'srichter', [u'newtag'])
 
 This is our first and only entry in the intid util
 
@@ -580,3 +580,42 @@
    1
    >>> sorted(engine.getItems())[0] == intIds.refs.keys()[0]
    True
+
+
+Renaming Tags
+-------------
+
+It is also possible to rename tags globally in the engine.
+
+   >>> tagging.update(u'srichter', [u'tagtorename', u'usa'])
+   >>> tagging.update(u'jukart', [
+   ...     u'tagtorename', u'someothertag', u'renamedtag'])
+   >>> engine.update(123, 'jukart', [u'tagtorename'])
+   >>> sorted(engine.getTags())
+   [u'renamedtag', u'someothertag', u'tagtorename', u'usa']
+   >>> sorted(engine.getTags(users=[u'jukart']))
+   [u'renamedtag', u'someothertag', u'tagtorename']
+   >>> len(sorted(engine.getItems(tags=[u'tagtorename'])))
+   2
+   >>> len(sorted(engine.getItems(tags=[u'renamedtag'])))
+   1
+   >>> sorted(engine.getTags(users=[u'srichter']))
+   [u'tagtorename', u'usa']
+
+The rename method returns the number of renamed tag objects.
+
+   >>> engine.rename(u'tagtorename', u'renamedtag')
+   3
+   >>> sorted(engine.getTags())
+   [u'renamedtag', u'someothertag', u'usa']
+
+Tags are joined if the new name already exists.
+
+   >>> sorted(engine.getTags(users=[u'jukart']))
+   [u'renamedtag', u'someothertag']
+   >>> sorted(engine.getTags(users=[u'srichter']))
+   [u'renamedtag', u'usa']
+   >>> len(sorted(engine.getItems(tags=[u'tagtorename'])))
+   0
+   >>> len(sorted(engine.getItems(tags=[u'renamedtag'])))
+   2

Modified: lovely.tag/trunk/src/lovely/tag/configure.zcml
===================================================================
--- lovely.tag/trunk/src/lovely/tag/configure.zcml	2007-01-08 13:29:07 UTC (rev 71803)
+++ lovely.tag/trunk/src/lovely/tag/configure.zcml	2007-01-08 13:29:41 UTC (rev 71804)
@@ -34,7 +34,7 @@
         />
     <require
         permission="lovely.tag.ManageEngine"
-        attributes="cleanStaleItems delete"
+        attributes="cleanStaleItems delete rename"
         />
     <require
         permission="lovely.tag.AccessTag"

Modified: lovely.tag/trunk/src/lovely/tag/engine.py
===================================================================
--- lovely.tag/trunk/src/lovely/tag/engine.py	2007-01-08 13:29:07 UTC (rev 71803)
+++ lovely.tag/trunk/src/lovely/tag/engine.py	2007-01-08 13:29:41 UTC (rev 71804)
@@ -291,6 +291,22 @@
                 cleaned.append(uid)
         return cleaned
 
+    def rename(self, old, new):
+        """rename tag @old to @new"""
+
+        if old == new:
+            return 0
+        tagIds = set(self._name_to_tagids.get(old, ()))
+        for tagId in tagIds:
+            tagObj = self._tag_ids.getObject(tagId)
+            tagObj.name = new
+        newTagIds = set(self._name_to_tagids.get(new, ()))
+        newTagIds.update(tagIds)
+        self._name_to_tagids[new] = newTagIds
+        del self._name_to_tagids[old]
+        return len(tagIds)
+        
+
 @component.adapter(IIntIdRemovedEvent)
 def removeItemSubscriber(event):
     

Modified: lovely.tag/trunk/src/lovely/tag/interfaces.py
===================================================================
--- lovely.tag/trunk/src/lovely/tag/interfaces.py	2007-01-08 13:29:07 UTC (rev 71803)
+++ lovely.tag/trunk/src/lovely/tag/interfaces.py	2007-01-08 13:29:41 UTC (rev 71804)
@@ -111,6 +111,11 @@
         e.g. to delete all entries of a user do:
         delete(user=u'username')
         """
+
+    def rename(old, new):
+        """rename tags from @old to @new, this method joins the tags
+        if tags with the new name do exist"""
+        
     
 class ITaggingStatistics(zope.interface.Interface):
     """A tagging engine that provides statistical information about itself"""



More information about the Checkins mailing list