[Zope3-checkins] CVS: Zope3/src/zope/app/dublincore - timeannotators.py:1.5

Garrett Smith cvs-admin at zope.org
Thu Oct 23 15:04:09 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/dublincore
In directory cvs.zope.org:/tmp/cvs-serv19465/src/zope/app/dublincore

Modified Files:
	timeannotators.py 
Log Message:
Setting an object's DC modified when the object is created. This ensures
DC modified can be meaningfully compared between any two objects.


=== Zope3/src/zope/app/dublincore/timeannotators.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/dublincore/timeannotators.py:1.4	Fri Jun  6 17:21:46 2003
+++ Zope3/src/zope/app/dublincore/timeannotators.py	Thu Oct 23 15:04:09 2003
@@ -23,18 +23,35 @@
 from zope.app.interfaces.event import ISubscriber
 from zope.interface import implements
 
-class DCTimeAnnotatorClass:
+class DCTimeAnnotatorBase:
     """Update Dublin-Core time property
     """
     implements(ISubscriber)
 
-    def __init__(self, property):
-        self.property = property
-
     def notify(self, event):
         dc = queryAdapter(event.object, IZopeDublinCore)
         if dc is not None:
-            setattr(dc, self.property, datetime.utcnow())
+            self.annotate(dc)
+
+    def annotate(self, dc):
+        raise RuntimeError, 'annotate not implemented'
+
+
+class ModifiedAnnotatorClass(DCTimeAnnotatorBase):
+    """Updates DC modified when an object is modified."""
+
+    def annotate(self, dc):
+        dc.modified = datetime.utcnow()
+
+
+class CreatedAnnotatorClass(DCTimeAnnotatorBase):
+    """Sets DC created and modified when an object is created."""
+
+    def annotate(self, dc):
+        now = datetime.utcnow()
+        dc.created = now
+        dc.modified = now
+
 
-ModifiedAnnotator = DCTimeAnnotatorClass('modified')
-CreatedAnnotator = DCTimeAnnotatorClass('created')
+ModifiedAnnotator = ModifiedAnnotatorClass()
+CreatedAnnotator = CreatedAnnotatorClass()




More information about the Zope3-Checkins mailing list