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