def compute_changes(self, save=False): """ Instance method to compute the deltas for a given audit instance. Assumes two things: 1: self.archived_data must be set 2: self.prev_id must be set too. returns None """ if self.prev_id is None: logging.error("Error, trying to compute changes where a previous pointer isn't set") return None if self.archived_data is None: logging.error("Error, trying to compute changes when the archived_data for CURRENT has not been set") return None prev_rev = self.prev() #sanity check if prev_rev.revision_checksum == self.revision_checksum: return None if (self.archived_data.get('doc_type', None) == 'XFormInstance' and prev_rev.archived_data.get('doc_type', None) == 'XFormInstance'): #it's an xforminstance - hackishly just inspect the form instance removed, added, changed = utils.dict_diff(self.archived_data['form'], prev_rev.archived_data['form']) else: #all other models compare the json directly removed, added, changed = utils.dict_diff(self.archived_data, prev_rev.archived_data) self.removed = removed self.added = added self.changed = changed if save: self.save()
def compute_changes(self, save=False): """ Instance method to compute the deltas for a given audit instance. Assumes two things: 1: self.archived_data must be set 2: self.prev_id must be set too. returns None """ if self.prev_id is None: log.error("Error, trying to compute changes where a previous pointer isn't set") return None if self.archived_data is None: log.error("Error, trying to compute changes when the archived_data for CURRENT has not been set") return None prev_rev = self.prev() if prev_rev.revision_checksum == self.revision_checksum: #sanity check, do nothing at no changes return None removed, added, changed = utils.dict_diff(self.archived_data, prev_rev.to_json()['archived_data']) self.removed = removed self.added = added self.changed = changed if save: self.save()