def edit(request, obj, appstruct, pre_save=None): object_id=obj._id object_path=obj.resource_path() old_values = obj.get_schema_values() obj.set_appstruct(appstruct) if pre_save: pre_save(obj, request, appstruct) new_values = obj.get_schema_values() changes = diff_dictionaries(old_values, new_values) if not changes: return False obj.save() log_history(request, 'edit', ids=[object_id], object_path=object_path, changes=changes) return True
def revert(request, obj, history_id): hc = HistoryCollection(request) history_item = hc.get_history_item(history_id) history_time = history_item['time'] object_id=obj._id object_path=obj.resource_path() old_values = obj.get_schema_values() hc.apply_history(obj, history_id) new_values = obj.get_schema_values() changes = diff_dictionaries(old_values, new_values) if not changes: return False obj.save() log_history(request, 'revert', ids=[object_id], object_path=object_path, changes=changes, history_id=history_id, history_time=history_time) return True