web/views/editcontroller.py
changeset 1162 f210dce0dc47
parent 0 b97547f5f1fa
child 1263 01152fffd593
equal deleted inserted replaced
1161:936c311010fc 1162:f210dce0dc47
   164 
   164 
   165     def _action_delete(self):
   165     def _action_delete(self):
   166         self.delete_entities(self.req.edited_eids(withtype=True))
   166         self.delete_entities(self.req.edited_eids(withtype=True))
   167         return self.reset()
   167         return self.reset()
   168 
   168 
   169     def _needs_edition(self, rtype, formparams):
   169     def _needs_edition(self, rtype, formparams, entity):
   170         """returns True and and the new value if `rtype` was edited"""
   170         """returns True and and the new value if `rtype` was edited"""
   171         editkey = 'edits-%s' % rtype
   171         editkey = 'edits-%s' % rtype
   172         if not editkey in formparams:
   172         if not editkey in formparams:
   173             return False, None # not edited
   173             return False, None # not edited
   174         value = formparams.get(rtype) or None
   174         value = formparams.get(rtype) or None
   175         if (formparams.get(editkey) or None) == value:
   175         if entity.has_eid() and (formparams.get(editkey) or None) == value:
   176             return False, None # not modified
   176             return False, None # not modified
   177         if value == INTERNAL_FIELD_VALUE:
   177         if value == INTERNAL_FIELD_VALUE:
   178             value = None        
   178             value = None        
   179         return True, value
   179         return True, value
   180 
   180 
   181     def handle_attribute(self, entity, rschema, formparams):
   181     def handle_attribute(self, entity, rschema, formparams):
   182         """append to `relations` part of the rql query to edit the
   182         """append to `relations` part of the rql query to edit the
   183         attribute described by the given schema if necessary
   183         attribute described by the given schema if necessary
   184         """
   184         """
   185         attr = rschema.type
   185         attr = rschema.type
   186         edition_needed, value = self._needs_edition(attr, formparams)
   186         edition_needed, value = self._needs_edition(attr, formparams, entity)
   187         if not edition_needed:
   187         if not edition_needed:
   188             return
   188             return
   189         # test if entity class defines a special handler for this attribute
   189         # test if entity class defines a special handler for this attribute
   190         custom_edit = getattr(entity, 'custom_%s_edit' % attr, None)
   190         custom_edit = getattr(entity, 'custom_%s_edit' % attr, None)
   191         if custom_edit:
   191         if custom_edit: