[Checkins] SVN: lovely.tag/trunk/src/lovely/tag/ Ignore component lookup errors if we try to remove all tags of an object.

Jürgen Kartnaller juergen at kartnaller.at
Fri Oct 20 02:23:50 EDT 2006


Log message for revision 70834:
  Ignore component lookup errors if we try to remove all tags of an object.
  
    If we update without tags it is possible that we do this
    because an object has been deleted. This is usually done in an
    event handler for ObjectRemovedEvent. If we would raise an
    exeption in this case it is not possible to delete a site.
  
  

Changed:
  U   lovely.tag/trunk/src/lovely/tag/README.txt
  U   lovely.tag/trunk/src/lovely/tag/tagging.py

-=-
Modified: lovely.tag/trunk/src/lovely/tag/README.txt
===================================================================
--- lovely.tag/trunk/src/lovely/tag/README.txt	2006-10-20 05:27:06 UTC (rev 70833)
+++ lovely.tag/trunk/src/lovely/tag/README.txt	2006-10-20 06:23:49 UTC (rev 70834)
@@ -294,10 +294,6 @@
 Using Named Tagging Engines
 ---------------------------
 
-  >>> namedEngine = tag.TaggingEngine()
-  >>> zope.component.provideUtility(namedEngine, tag.interfaces.ITaggingEngine,
-  ...                               name='IAmNamed')
-
   >>> class INamedTagging(tag.interfaces.ITagging):
   ...     pass
   >>> class NamedTagging(tag.Tagging):
@@ -307,8 +303,31 @@
   >>> zope.component.provideAdapter(NamedTagging,
   ...                               (tag.interfaces.ITaggable,),
   ...                               INamedTagging)
+
   >>> namedTagging = INamedTagging(image)
   >>> namedTagging.tags = ['named1', 'named2']
+  >>> namedTagging.update(u'jukart', [u'works', u'hard'])
+  Traceback (most recent call last):
+  ...
+  ComponentLookupError: (<InterfaceClass lovely.tag.interfaces.ITaggingEngine>, 'IAmNamed')
+
+We have no named tagging engine registered yet. Let's see what happens if we
+update with an empty list of tags.
+
+  >>> namedTagging.update(u'jukart', [])
+
+If we update without tags it is possible that we do this because an object has
+been deleted. This is usually done in an event handler for ObjectRemovedEvent.
+If we would raise an exeption in this case it is not possible to delete a site.
+
+Now we register a named tagging engine.
+
+  >>> namedEngine = tag.TaggingEngine()
+  >>> zope.component.provideUtility(namedEngine, tag.interfaces.ITaggingEngine,
+  ...                               name='IAmNamed')
+
+  >>> namedTagging = INamedTagging(image)
+  >>> namedTagging.tags = ['named1', 'named2']
   >>> sorted(namedTagging.getTags())
   []
   >>> namedTagging.update(u'jukart', [u'works', u'hard'])

Modified: lovely.tag/trunk/src/lovely/tag/tagging.py
===================================================================
--- lovely.tag/trunk/src/lovely/tag/tagging.py	2006-10-20 05:27:06 UTC (rev 70833)
+++ lovely.tag/trunk/src/lovely/tag/tagging.py	2006-10-20 06:23:49 UTC (rev 70834)
@@ -49,7 +49,16 @@
 
     def update(self, user, tags):
         """See interfaces.ITagging"""
-        return self.engine.update(self.docId, user, tags)
+        try:
+            self.engine.update(self.docId, user, tags)
+        except zope.component.ComponentLookupError:
+            # special behaviour :
+            #  If we update without tags it is possible that we do this
+            #  because an object has been deleted. This is usually done in an
+            #  event handler for ObjectRemovedEvent. If we would raise an
+            #  exeption in this case it is not possible to delete a site.
+            if tags:
+                raise
 
     def getTags(self, users=None):
         """See interfaces.ITagging"""
@@ -99,6 +108,15 @@
         def fset(self, value):
             if value is None:
                 return
-            return self.engine.update(self.docId, self._pid, value)
+            try:
+                self.engine.update(self.docId, self._pid, value)
+            except zope.component.ComponentLookupError:
+                # special behaviour :
+                #  If we update without tags it is possible that we do this
+                #  because an object has been deleted. This is usually done in an
+                #  event handler for ObjectRemovedEvent. If we would raise an
+                #  exeption in this case it is not possible to delete a site.
+                if value:
+                    raise
         return property(**locals())
 



More information about the Checkins mailing list