[Checkins] SVN: zope.app.file/branches/3.4/ Include information about which attributes changed in the

Philipp von Weitershausen philikon at philikon.de
Fri Nov 9 14:43:24 EST 2007


Log message for revision 81664:
    Include information about which attributes changed in the
    ``IObjectModifiedEvent`` after upload.
  
    This fixes https://bugs.launchpad.net/zope3/+bug/98483.
  
  
  

Changed:
  U   zope.app.file/branches/3.4/CHANGES.txt
  U   zope.app.file/branches/3.4/src/zope/app/file/browser/file.py

-=-
Modified: zope.app.file/branches/3.4/CHANGES.txt
===================================================================
--- zope.app.file/branches/3.4/CHANGES.txt	2007-11-09 19:42:14 UTC (rev 81663)
+++ zope.app.file/branches/3.4/CHANGES.txt	2007-11-09 19:43:23 UTC (rev 81664)
@@ -2,11 +2,14 @@
 CHANGES
 =======
 
-3.4.2 (unreleased)
+3.4.2 (2007-11-09)
 ------------------
 
-- ...
+- Include information about which attributes changed in the
+  ``IObjectModifiedEvent`` after upload.
 
+  This fixes https://bugs.launchpad.net/zope3/+bug/98483.
+
 3.4.1 (2007-10-31)
 ------------------
 

Modified: zope.app.file/branches/3.4/src/zope/app/file/browser/file.py
===================================================================
--- zope.app.file/branches/3.4/src/zope/app/file/browser/file.py	2007-11-09 19:42:14 UTC (rev 81663)
+++ zope.app.file/branches/3.4/src/zope/app/file/browser/file.py	2007-11-09 19:43:23 UTC (rev 81664)
@@ -339,12 +339,12 @@
         We install an event logger so we can see the events generated.
 
         >>> def eventLog(event):
-        ...    print event
+        ...    print event.__class__.__name__, event.descriptions[0].attributes
         >>> zope.event.subscribers.append(eventLog)
 
         >>> view.setData({'contentType': 'text/plain; charset=ISO-8859-13',
         ...               'data': u'text \u0105'}) # doctest:+ELLIPSIS
-        <zope.app.event.objectevent.ObjectModifiedEvent object at ...>
+        ObjectModifiedEvent ('data', 'contentType')
         u'Updated on ${date_time}'
 
         >>> view.context.contentType
@@ -441,18 +441,28 @@
     def setData(self, data):
         charset = extractCharset(data['contentType'])
         try:
-            self.context.data = data['data'].encode(charset)
+            encodeddata = data['data'].encode(charset)
         except LookupError:
             raise UnknownCharset(charset)
         except UnicodeEncodeError:
             raise CharsetTooWeak(charset)
-        self.context.contentType = data['contentType']
+        
+        modified = []
+        if encodeddata != self.context.data:
+            self.context.data = encodeddata
+            modified.append('data')
+        
+        if self.context.contentType != data['contentType']:
+            self.context.contentType = data['contentType']
+            modified.append('contentType')
         formatter = self.request.locale.dates.getFormatter('dateTime',
                                                            'medium')
+        if modified:
+            event = lifecycleevent.ObjectModifiedEvent(
+                self.context,
+                lifecycleevent.Attributes(IFile, *modified))
+            zope.event.notify(event)
 
-        event = lifecycleevent.ObjectModifiedEvent(self.context)
-        zope.event.notify(event)
-
         return _("Updated on ${date_time}",
                  mapping={'date_time': formatter.format(datetime.utcnow())})
 



More information about the Checkins mailing list