[Checkins] SVN: lovely.tag/trunk/ Fixed an important bug of the weight being messed up on the same tag updated for the same user. Fixed the bug and added a test to demonstrate the behavior. The changelog has been updated.

Souheil CHELFOUH souheil at chelfouh.com
Thu Sep 24 12:18:08 EDT 2009


Log message for revision 104489:
  Fixed an important bug of the weight being messed up on the same tag updated for the same user. Fixed the bug and added a test to demonstrate the behavior. The changelog has been updated.

Changed:
  U   lovely.tag/trunk/CHANGES.txt
  U   lovely.tag/trunk/setup.py
  U   lovely.tag/trunk/src/lovely/tag/README.txt
  U   lovely.tag/trunk/src/lovely/tag/engine.py
  U   lovely.tag/trunk/src/lovely/tag/tag.py

-=-
Modified: lovely.tag/trunk/CHANGES.txt
===================================================================
--- lovely.tag/trunk/CHANGES.txt	2009-09-24 15:33:06 UTC (rev 104488)
+++ lovely.tag/trunk/CHANGES.txt	2009-09-24 16:18:07 UTC (rev 104489)
@@ -5,8 +5,12 @@
 1.1.0 (unreleased)
 ------------------
 
-- ...
+- Fixed error on tag handling in update : tag where registered more
+  than once for same user, item and tag  as with set what imports is
+  hash and not cmp. Added a test to put this in evidence with
+  getCloud. [trollfot]
 
+
 1.0.0 (2009-07-24)
 ------------------
 
@@ -14,6 +18,7 @@
 
 - Cleanup release boilerplate.
 
+
 0.3.0b2 (2007-07-18)
 --------------------
 

Modified: lovely.tag/trunk/setup.py
===================================================================
--- lovely.tag/trunk/setup.py	2009-09-24 15:33:06 UTC (rev 104488)
+++ lovely.tag/trunk/setup.py	2009-09-24 16:18:07 UTC (rev 104489)
@@ -51,7 +51,7 @@
     extras_require = dict(
         test = ['zope.app.testing',
                 'zope.app.catalog',
-                'zope.keyreference',
+                'zope.app.keyreference',
                 'z3c.sampledata']
         ),
     install_requires = [

Modified: lovely.tag/trunk/src/lovely/tag/README.txt
===================================================================
--- lovely.tag/trunk/src/lovely/tag/README.txt	2009-09-24 15:33:06 UTC (rev 104488)
+++ lovely.tag/trunk/src/lovely/tag/README.txt	2009-09-24 16:18:07 UTC (rev 104489)
@@ -25,7 +25,7 @@
 adapted to key references:
 
   >>> import zope.component
-  >>> from zope.keyreference import testing
+  >>> from zope.app.keyreference import testing
 
   >>> zope.component.provideAdapter(testing.SimpleKeyReference)
 
@@ -448,6 +448,22 @@
   [(u'Austria', 1), (u'USA', 1), (u'austria', 1),
    (u'lovely', 1), (u'personal', 1), (u'work', 1)]
 
+Re-updating tags for same user does not affect cloud weight
+
+   >>> engine.update(1, u'jodok', [u'USA',])
+   >>> sorted(engine.getCloud(items=[1, 2, 3], users=[u'srichter', u'jodok']))
+   [(u'Austria', 1), (u'USA', 1), (u'austria', 1),
+   (u'lovely', 1), (u'personal', 1), (u'work', 1)]
+
+
+Re-updating tags for same user does not affect cloud weight
+
+  >>> engine.update(1, u'jodok', [u'USA',])
+  >>> sorted(engine.getCloud(items=[1, 2, 3], users=[u'srichter', u'jodok']))
+  [(u'Austria', 1), (u'USA', 1), (u'austria', 1),
+   (u'lovely', 1), (u'personal', 1), (u'work', 1)]
+
+
 Related Tags
 ------------
 

Modified: lovely.tag/trunk/src/lovely/tag/engine.py
===================================================================
--- lovely.tag/trunk/src/lovely/tag/engine.py	2009-09-24 15:33:06 UTC (rev 104488)
+++ lovely.tag/trunk/src/lovely/tag/engine.py	2009-09-24 16:18:07 UTC (rev 104489)
@@ -91,19 +91,20 @@
         for t in tags:
             tags_tags.update(self._name_to_tagids.get(t, ()))
         old_tag_ids = tags_item.intersection(tags_user)
-        # any tags of the same user/item that are not in tags
-        old_tag_ids = old_tag_ids.difference(tags_tags)
+        # any tags of the same user/item that are  in tags
+        common_tag_ids = old_tag_ids.intersection(tags_tags)
             
-        old_tags = set([self._tagid_to_obj[id]
+        common_tags = set([self._tagid_to_obj[id].brain()
                         for id in old_tag_ids])
 
-        new_tags = set([tag.Tag(item, user, tagName)
+        new_tags = set([tag.Tag(item, user, tagName).brain()
                         for tagName in tags])
 
-        add_tags = new_tags.difference(old_tags)
+        add_tags = new_tags.difference(common_tags)
         
         add_tag_ids = []
-        for tagObj in add_tags:
+        for tagBrain in add_tags:
+            tagObj = tag.Tag.from_brain(tagBrain)
             id = self._add(tagObj)
             add_tag_ids.append(id)
             ids = self._user_to_tagids.get(user)
@@ -123,7 +124,7 @@
                 self._name_to_tagids[tagObj.name] = IOBTree.IOSet((id,))
             else:
                 ids.insert(id)
-        del_tag_ids = old_tag_ids.difference(add_tag_ids)
+        del_tag_ids = old_tag_ids.difference(tags_tags)
         self._delTags(del_tag_ids)
 
     def _delTags(self, del_tag_ids):

Modified: lovely.tag/trunk/src/lovely/tag/tag.py
===================================================================
--- lovely.tag/trunk/src/lovely/tag/tag.py	2009-09-24 15:33:06 UTC (rev 104488)
+++ lovely.tag/trunk/src/lovely/tag/tag.py	2009-09-24 16:18:07 UTC (rev 104489)
@@ -48,6 +48,14 @@
         return cmp((self.item, self.user, self.name),
                    (other.item, other.user, other.name))
 
+    def brain(self):
+        """ representation to build sets"""
+        return (self.item, self.user, self.name)
+
+    @classmethod
+    def from_brain(cls, brain):
+        return cls(*brain)
+
     def __repr__(self):
         return '<%s %r for %i by %r>' %(
             self.__class__.__name__, self.name, self.item, self.user)



More information about the checkins mailing list