fix for booelan attribute which have empty string as false value and didn't work if default value for this attribute was True.
authorStephanie Marcu <stephanie.marcu@logilab.fr>
Thu, 26 Mar 2009 14:55:44 +0100
changeset 1162 f210dce0dc47
parent 1161 936c311010fc
child 1167 d9865bc720a9
fix for booelan attribute which have empty string as false value and didn't work if default value for this attribute was True.
web/views/editcontroller.py
--- a/web/views/editcontroller.py	Thu Mar 26 09:09:58 2009 +0100
+++ b/web/views/editcontroller.py	Thu Mar 26 14:55:44 2009 +0100
@@ -166,13 +166,13 @@
         self.delete_entities(self.req.edited_eids(withtype=True))
         return self.reset()
 
-    def _needs_edition(self, rtype, formparams):
+    def _needs_edition(self, rtype, formparams, entity):
         """returns True and and the new value if `rtype` was edited"""
         editkey = 'edits-%s' % rtype
         if not editkey in formparams:
             return False, None # not edited
         value = formparams.get(rtype) or None
-        if (formparams.get(editkey) or None) == value:
+        if entity.has_eid() and (formparams.get(editkey) or None) == value:
             return False, None # not modified
         if value == INTERNAL_FIELD_VALUE:
             value = None        
@@ -183,7 +183,7 @@
         attribute described by the given schema if necessary
         """
         attr = rschema.type
-        edition_needed, value = self._needs_edition(attr, formparams)
+        edition_needed, value = self._needs_edition(attr, formparams, entity)
         if not edition_needed:
             return
         # test if entity class defines a special handler for this attribute