[Checkins] SVN: CMF/trunk/CMFDefault/ - improved safety belt handling, using the new Document methods

Yvo Schubbe y.2007- at wcm-solutions.de
Wed Feb 7 05:18:32 EST 2007


Log message for revision 72414:
  - improved safety belt handling, using the new Document methods

Changed:
  U   CMF/trunk/CMFDefault/browser/document.py
  U   CMF/trunk/CMFDefault/formlib/form.py

-=-
Modified: CMF/trunk/CMFDefault/browser/document.py
===================================================================
--- CMF/trunk/CMFDefault/browser/document.py	2007-02-07 09:37:45 UTC (rev 72413)
+++ CMF/trunk/CMFDefault/browser/document.py	2007-02-07 10:18:25 UTC (rev 72414)
@@ -51,7 +51,8 @@
     """Schema for document views.
     """
 
-    safety_belt = ASCIILine()
+    safety_belt = ASCIILine(
+        required=False)
 
     title = TextLine(
         title=_(u'Title'),
@@ -84,7 +85,7 @@
     implements(IDocumentSchema)
 
     safety_belt = ProxyFieldProperty(IDocumentSchema['safety_belt'],
-                                     'SafetyBelt')
+                                     '_safety_belt')
     title = ProxyFieldProperty(IDocumentSchema['title'], 'Title')
     description = ProxyFieldProperty(IDocumentSchema['description'],
                                      'Description')
@@ -129,15 +130,19 @@
         body = data.get('upload')
         if body:
             data['text'] = body.decode(self._getDefaultCharset())
-        super(DocumentEditView, self)._handle_success(action, data)
+        changed = super(DocumentEditView, self)._handle_success(action, data)
+        if changed:
+            self.context.updateSafetyBelt(data.get('safety_belt'))
+        return changed
 
     def handle_validate(self, action, data):
         errors = super(DocumentEditView, self).handle_validate(action, data)
         if errors:
             return errors
         safety_belt = self.request.form['form.safety_belt']
-        if not self.context._safety_belt_update(safety_belt):
+        if not self.context.isValidSafetyBelt(safety_belt):
             return (_(u'Intervening changes from elsewhere detected. Please '
                       u'refetch the document and reapply your changes.'),)
-        self.request.form['form.safety_belt'] = self.context.SafetyBelt()
+        # make sure applyChanges doesn't try to update safety_belt
+        self.request.form['form.safety_belt'] = self.context._safety_belt
         return None

Modified: CMF/trunk/CMFDefault/formlib/form.py
===================================================================
--- CMF/trunk/CMFDefault/formlib/form.py	2007-02-07 09:37:45 UTC (rev 72413)
+++ CMF/trunk/CMFDefault/formlib/form.py	2007-02-07 10:18:25 UTC (rev 72414)
@@ -134,14 +134,16 @@
                 data[k] = set(v)
             elif isinstance(v, datetime) and v.tzname() is None:
                 data[k] = parseDatetimetz(str(v))
-        if form.applyChanges(self.context, self.form_fields, data,
-                             self.adapters):
+        changed = form.applyChanges(self.context, self.form_fields, data,
+                                    self.adapters)
+        if changed:
             self.context.reindexObject()
             obj_type = translate(self.context.Type(), self.context)
             self.status = _(u'${obj_type} changed.',
                             mapping={'obj_type': obj_type})
         else:
             self.status = _(u'Nothing to change.')
+        return changed
 
     def handle_change_success(self, action, data):
         self._handle_success(action, data)



More information about the Checkins mailing list