mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
14147 remove override of to_objectchange
This commit is contained in:
parent
30eb48b580
commit
033b10b951
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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',
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user