14147 remove override of to_objectchange

This commit is contained in:
Arthur 2023-12-14 11:46:26 -08:00
parent 30eb48b580
commit 033b10b951
13 changed files with 17 additions and 30 deletions

View File

@ -239,8 +239,7 @@ class CircuitTermination(
raise ValidationError("A circuit termination cannot attach to both a site and a provider network.") raise ValidationError("A circuit termination cannot attach to both a site and a provider network.")
def to_objectchange(self, action): def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None: objectchange = super().to_objectchange(action)
return None
objectchange.related_object = self.circuit objectchange.related_object = self.circuit
return objectchange return objectchange

View File

@ -386,8 +386,7 @@ class CableTermination(ChangeLoggedModel):
cache_related_objects.alters_data = True cache_related_objects.alters_data = True
def to_objectchange(self, action): def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None: objectchange = super().to_objectchange(action)
return None
objectchange.related_object = self.termination objectchange.related_object = self.termination
return objectchange return objectchange

View File

@ -91,8 +91,7 @@ class ComponentTemplateModel(ChangeLoggedModel, TrackingModelMixin):
self._original_device_type = self.__dict__.get('device_type_id') self._original_device_type = self.__dict__.get('device_type_id')
def to_objectchange(self, action): def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None: objectchange = super().to_objectchange(action)
return None
objectchange.related_object = self.device_type objectchange.related_object = self.device_type
return objectchange return objectchange
@ -139,8 +138,7 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
) )
def to_objectchange(self, action): def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None: objectchange = super().to_objectchange(action)
return None
if self.device_type is not None: if self.device_type is not None:
objectchange.related_object = self.device_type objectchange.related_object = self.device_type
elif self.module_type is not None: elif self.module_type is not None:

View File

@ -93,8 +93,7 @@ class ComponentModel(NetBoxModel):
return self.name return self.name
def to_objectchange(self, action): def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None: objectchange = super().to_objectchange(action)
return None
objectchange.related_object = self.device objectchange.related_object = self.device
return objectchange return objectchange

View File

@ -135,3 +135,7 @@ class ObjectChange(models.Model):
def get_action_color(self): def get_action_color(self):
return ObjectChangeActionChoices.colors.get(self.action) return ObjectChangeActionChoices.colors.get(self.action)
@property
def has_changes(self):
return self.prechange_data != self.postchange_data

View File

@ -688,8 +688,7 @@ class ImageAttachment(ChangeLoggedModel):
return None return None
def to_objectchange(self, action): def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None: objectchange = super().to_objectchange(action)
return None
objectchange.related_object = self.parent objectchange.related_object = self.parent
return objectchange return objectchange

View File

@ -80,7 +80,7 @@ def handle_changed_object(sender, instance, **kwargs):
) )
else: else:
objectchange = instance.to_objectchange(action) objectchange = instance.to_objectchange(action)
if objectchange: if objectchange and objectchange.has_changes:
objectchange.user = request.user objectchange.user = request.user
objectchange.request_id = request.id objectchange.request_id = request.id
objectchange.save() objectchange.save()

View File

@ -208,6 +208,7 @@ class ChangeLogViewTest(ModelViewTestCase):
self.assertEqual(objectchange.prechange_data['slug'], sites[0].slug) self.assertEqual(objectchange.prechange_data['slug'], sites[0].slug)
self.assertEqual(objectchange.postchange_data, None) self.assertEqual(objectchange.postchange_data, None)
@override_settings(CHANGELOG_SKIP_EMPTY_CHANGES=False)
def test_update_object_change(self): def test_update_object_change(self):
site = Site( site = Site(
name='Site 1', name='Site 1',

View File

@ -902,8 +902,7 @@ class IPAddress(PrimaryModel):
return attrs return attrs
def to_objectchange(self, action): def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None: objectchange = super().to_objectchange(action)
return None
objectchange.related_object = self.assigned_object objectchange.related_object = self.assigned_object
return objectchange return objectchange

View File

@ -94,14 +94,6 @@ class ChangeLoggingMixin(models.Model):
if get_config().CHANGELOG_SKIP_EMPTY_CHANGES: if get_config().CHANGELOG_SKIP_EMPTY_CHANGES:
exclude_fields = ['last_updated',] exclude_fields = ['last_updated',]
postchange_data = None
if action in (ObjectChangeActionChoices.ACTION_CREATE, ObjectChangeActionChoices.ACTION_UPDATE):
postchange_data = self.serialize_object(exclude_fields=exclude_fields)
if get_config().CHANGELOG_SKIP_EMPTY_CHANGES and action == ObjectChangeActionChoices.ACTION_UPDATE and hasattr(self, '_prechange_snapshot'):
if postchange_data == self._prechange_snapshot:
return None
objectchange = ObjectChange( objectchange = ObjectChange(
changed_object=self, changed_object=self,
object_repr=str(self)[:200], object_repr=str(self)[:200],
@ -110,7 +102,7 @@ class ChangeLoggingMixin(models.Model):
if hasattr(self, '_prechange_snapshot'): if hasattr(self, '_prechange_snapshot'):
objectchange.prechange_data = self._prechange_snapshot objectchange.prechange_data = self._prechange_snapshot
if action in (ObjectChangeActionChoices.ACTION_CREATE, ObjectChangeActionChoices.ACTION_UPDATE): if action in (ObjectChangeActionChoices.ACTION_CREATE, ObjectChangeActionChoices.ACTION_UPDATE):
objectchange.postchange_data = postchange_data objectchange.postchange_data = self.serialize_object(exclude_fields=exclude_fields)
return objectchange return objectchange

View File

@ -171,7 +171,6 @@ class ContactAssignment(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, Chan
) )
def to_objectchange(self, action): def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None: objectchange = super().to_objectchange(action)
return None
objectchange.related_object = self.object objectchange.related_object = self.object
return objectchange return objectchange

View File

@ -298,8 +298,7 @@ class ComponentModel(NetBoxModel):
return self.name return self.name
def to_objectchange(self, action): def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None: objectchange = super().to_objectchange(action)
return None
objectchange.related_object = self.virtual_machine objectchange.related_object = self.virtual_machine
return objectchange return objectchange

View File

@ -178,7 +178,6 @@ class TunnelTermination(CustomFieldsMixin, CustomLinksMixin, TagsMixin, ChangeLo
}) })
def to_objectchange(self, action): def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None: objectchange = super().to_objectchange(action)
return None
objectchange.related_object = self.tunnel objectchange.related_object = self.tunnel
return objectchange return objectchange