def log_netbox_change(account, old, new): """Log specific user initiated changes to netboxes""" # If this is a new netbox if not old: LogEntry.add_create_entry(account, new) return # Compare changes from old to new attribute_list = [ 'read_only', 'read_write', 'category', 'ip', 'room', 'organization', 'snmp_version', ] LogEntry.compare_objects( account, old, new, attribute_list, censored_attributes=['read_only', 'read_write'], )
def post(self, request, *args, **kwargs): old_object = copy.deepcopy(self.get_object()) response = super(TokenEdit, self).post(request, *args, **kwargs) messages.success(request, 'Token saved') LogEntry.compare_objects( request.account, old_object, self.get_object(), ['expires', 'permission', 'endpoints', 'comment']) return response
def log_account_change(actor, old, new): """Log change to account""" if not old: LogEntry.add_create_entry(actor, new) return attribute_list = ['login', 'name', 'password', 'ext_sync'] LogEntry.compare_objects(actor, old, new, attribute_list)
def test_compare_objects(self): j1 = Justification.objects.create(name='ferrari', description='Psst!') j2 = Justification.objects.create(name='lambo', description='Hush') LogEntry.compare_objects(self.justification, j1, j2, ('name', 'description'), ('description', )) l = LogEntry.objects.filter(verb=u'edit-justification-name').get() self.assertEqual( l.summary, u'testarossa edited lambo: name changed' u" from 'ferrari' to 'lambo'") l.delete() l = LogEntry.objects.filter( verb=u'edit-justification-description').get() self.assertEqual(l.summary, u'testarossa edited lambo: description changed') l.delete()