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.")
def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None:
return None
objectchange = super().to_objectchange(action)
objectchange.related_object = self.circuit
return objectchange

View File

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

View File

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

View File

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

View File

@ -135,3 +135,7 @@ class ObjectChange(models.Model):
def get_action_color(self):
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
def to_objectchange(self, action):
if (objectchange := super().to_objectchange(action)) is None:
return None
objectchange = super().to_objectchange(action)
objectchange.related_object = self.parent
return objectchange

View File

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

View File

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

View File

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

View File

@ -94,14 +94,6 @@ class ChangeLoggingMixin(models.Model):
if get_config().CHANGELOG_SKIP_EMPTY_CHANGES:
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(
changed_object=self,
object_repr=str(self)[:200],
@ -110,7 +102,7 @@ class ChangeLoggingMixin(models.Model):
if hasattr(self, '_prechange_snapshot'):
objectchange.prechange_data = self._prechange_snapshot
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

View File

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

View File

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

View File

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