def _serialize_changes(self): changes = {'object_id': self.object_id} for key, old_value in self.old_values.items(): new_value = self[key] if ( json_encode_extra(old_value) == json_encode_extra(new_value) ): continue if isinstance(old_value, MultiAttr): action = 'multi' else: action = 'update' change = {'action': action} if action == 'update': change['old'] = old_value change['new'] = new_value elif action == 'multi': change['remove'] = old_value.difference(new_value) change['add'] = new_value.difference(old_value) changes[key] = change return changes
def commit_state(self): if self.object_id is None: return 'created' if self._deleted: return 'deleted' for attribute_id, old_value in self.old_values.items(): if (json_encode_extra(self[attribute_id]) != json_encode_extra(old_value)): return 'changed' return 'consistent'
def _validate_commit(changes, servers): newer = [] for attribute_changes in changes: object_id = attribute_changes['object_id'] server = servers[object_id] for attr, change in attribute_changes.items(): if attr == 'object_id': continue action = change['action'] if action == 'new': if attr in server: newer.append((object_id, attr, server[attr])) elif action == 'update' or action == 'delete': try: if json_encode_extra(server[attr]) != str(change['old']): newer.append((object_id, attr, server[attr])) except KeyError: newer.append((object_id, attr, None)) return newer