def update(self, request): record = self._get_record() modified = self._get_record() update_record = False for key, val in six.iteritems(self._extract_data(request)): # Only setattr and save the model when a change has happened. if val != getattr(record, key): setattr(modified, key, val) update_record = True if self.can_update(request.user, record, modified=modified): if update_record: self._save(modified) try: tags = self._extract_tags(request) if tags: modified.tags.set(*tags) else: # If tags were in the request and set to nothing, we will # clear them all out. modified.tags.clear() except KeyError: pass ajax_updated.send(sender=record.__class__, instance=record) return encoder.encode(modified) else: raise AJAXError(403, _("Access to endpoint is forbidden"))
def update(self, request): record = self._get_record() modified = self._get_record() for key, val in list(self._extract_data(request).items()): setattr(modified, key, val) if self.can_update(request.user, record, modified=modified): self._save(modified) try: tags = self._extract_tags(request) if tags: modified.tags.set(*tags) else: # If tags were in the request and set to nothing, we will # clear them all out. modified.tags.clear() except KeyError: pass ajax_updated.send(sender=record.__class__, instance=record) return encoder.encode(modified) else: raise AJAXError(403, _("Access to endpoint is forbidden"))