def createEvent(thisCls, obj): h = thisCls() try: old = obj.__class__.get(obj.__class__.id == obj.id) except obj.__class__.DoesNotExist: old = {} h.obj_id = 0 h.event = 'insert' else: h.obj_id = old.id h.event = 'update' if obj.__class__.__name__ == 'Element': h.game = obj.id elif hasattr(obj, 'element'): h.game = obj.element h.old_obj = json.dumps(old, cls=MyEncoder) h.new_obj = json.dumps(obj, cls=MyEncoder) h.obj_class = obj.__class__.__name__ if hasattr(obj, 'type'): h.obj_type = obj.type else: h.obj_type = obj.__class__.__name__ if not h.obj_type: log.warning( 'While creating a history event had no obj_type not creating event. %s' % obj) return if h.event == 'insert' and dict_diff(old, obj.__dict__): h.save() if h.event == 'update' and dict_diff(old.__dict__, obj.__dict__): h.save()
def createEvent(thisCls, obj): h = thisCls() try: old = obj.__class__.get(obj.__class__.id == obj.id) except obj.__class__.DoesNotExist: old = {} h.obj_id = 0 h.event = 'insert' else: h.obj_id = old.id h.event = 'update' if obj.__class__.__name__ == 'Element': h.element = obj.id elif hasattr(obj, 'element'): h.element = obj.element h.old_obj = json.dumps(old, cls=MyEncoder) h.new_obj = json.dumps(obj, cls=MyEncoder) h.obj_class = obj.__class__.__name__ if hasattr(obj, 'type'): h.obj_type = obj.type else: h.obj_type = obj.__class__.__name__ if not h.obj_type: log.warning('While creating a history event had no obj_type not creating event. %s' % obj) return if h.event == 'insert' and dict_diff(old, obj.__dict__): h.save() if h.event == 'update' and dict_diff(old.__dict__, obj.__dict__): h.save()
def _humanDownload(self): data_o = self._old() data_n = self._new() if data_n and data_o: if self.event == 'update': if data_n['status'] != data_o['status']: return 'marked download as %s ' % Status.get(Status.id == data_n['status']) elif data_n['status'] == data_o['status'] and data_o['status'] == common.SNATCHED.id: return 'Download resantched: %s' % Download.get(Download.id == data_n['id']) diff = dict_diff(data_n, data_o) if diff: return '%s' % diff else: return 'Save without a data change.' else: return data_n['msg'] return 'this case of download history is not implemented'
def _humanDownload(self): data_o = self._old() data_n = self._new() if data_n and data_o: if self.event == "update": if data_n["status"] != data_o["status"]: return "marked download as %s " % Status.get(Status.id == data_n["status"]) elif data_n["status"] == data_o["status"] and data_o["status"] == common.SNATCHED.id: return "Download resantched: %s" % Download.get(Download.id == data_n["id"]) diff = dict_diff(data_n, data_o) if diff: return "%s" % diff else: return "Save without a data change." else: return data_n["msg"] return "this case of download history is not implemented"
def _humanElement(self): data_o = self._old() data_n = self._new() if data_n and data_o: if self.event == 'update': if 'status' in data_n: if data_n['status'] != data_o['status']: return 'new status %s ' % Status.get(Status.id == data_n['status']) elif data_n['status'] == data_o['status'] and data_o['status'] == common.SNATCHED.id: return 'Resantched: %s' % Element.get(Element.id == data_n['id']) diff = dict_diff(data_n, data_o) if diff: return '%s' % diff else: return 'Save without a data change.' else: return data_n['msg'] return 'this case of Element history is not implemented'
def _humanElement(self): data_o = self._old() data_n = self._new() if data_n and data_o: if self.event == "update": if "status" in data_n: if data_n["status"] != data_o["status"]: return "new status %s " % Status.get(Status.id == data_n["status"]) elif data_n["status"] == data_o["status"] and data_o["status"] == common.SNATCHED.id: return "Resantched: %s" % Element.get(Element.id == data_n["id"]) diff = dict_diff(data_n, data_o) if diff: return "%s" % diff else: return "Save without a data change." else: return data_n["msg"] return "this case of Element history is not implemented"
def _humanDownload(self): data_o = self._old() data_n = self._new() if data_n and data_o: if self.event == 'update': if data_n['status'] != data_o['status']: return 'marked download as %s ' % Status.get( Status.id == data_n['status']) elif data_n['status'] == data_o['status'] and data_o[ 'status'] == common.SNATCHED.id: return 'Download resantched: %s' % Download.get( Download.id == data_n['id']) diff = dict_diff(data_n, data_o) if diff: return '%s' % diff else: return 'Save without a data change.' else: return data_n['msg'] return 'this case of download history is not implemented'
def _humanElement(self): data_o = self._old() data_n = self._new() if data_n and data_o: if self.event == 'update': if 'status' in data_n: if data_n['status'] != data_o['status']: return 'new status %s ' % Status.get( Status.id == data_n['status']) elif data_n['status'] == data_o['status'] and data_o[ 'status'] == common.SNATCHED.id: return 'Resantched: %s' % Element.get( Element.id == data_n['id']) diff = dict_diff(data_n, data_o) if diff: return '%s' % diff else: return 'Save without a data change.' else: return data_n['msg'] return 'this case of Element history is not implemented'
def _humanConfig(self): data_o = self._old() data_n = self._new() if data_n and data_o: return '%s' % self._humanDict(dict_diff(data_n, data_o)) return 'unknown Config change'