Просмотр исходного кода

Rename parent attribute on CableTerminations to parent_object

Jeremy Stretch 5 лет назад
Родитель
Сommit
8e1fe6339e

+ 1 - 1
netbox/circuits/models.py

@@ -295,7 +295,7 @@ class CircuitTermination(ChangeLoggingMixin, BigIDModel, PathEndpoint, CableTerm
         return super().to_objectchange(action, related_object=circuit)
         return super().to_objectchange(action, related_object=circuit)
 
 
     @property
     @property
-    def parent(self):
+    def parent_object(self):
         return self.circuit
         return self.circuit
 
 
     def get_peer_termination(self):
     def get_peer_termination(self):

+ 14 - 14
netbox/dcim/models/device_components.py

@@ -84,8 +84,8 @@ class ComponentModel(PrimaryModel):
         return super().to_objectchange(action, related_object=device)
         return super().to_objectchange(action, related_object=device)
 
 
     @property
     @property
-    def parent(self):
-        return getattr(self, 'device', None)
+    def parent_object(self):
+        return self.device
 
 
 
 
 class CableTermination(models.Model):
 class CableTermination(models.Model):
@@ -152,6 +152,10 @@ class CableTermination(models.Model):
     def _occupied(self):
     def _occupied(self):
         return bool(self.mark_connected or self.cable_id)
         return bool(self.mark_connected or self.cable_id)
 
 
+    @property
+    def parent_object(self):
+        raise NotImplementedError("CableTermination models must implement parent_object()")
+
 
 
 class PathEndpoint(models.Model):
 class PathEndpoint(models.Model):
     """
     """
@@ -207,7 +211,7 @@ class PathEndpoint(models.Model):
 #
 #
 
 
 @extras_features('custom_fields', 'export_templates', 'webhooks')
 @extras_features('custom_fields', 'export_templates', 'webhooks')
-class ConsolePort(CableTermination, PathEndpoint, ComponentModel):
+class ConsolePort(ComponentModel, CableTermination, PathEndpoint):
     """
     """
     A physical console port within a Device. ConsolePorts connect to ConsoleServerPorts.
     A physical console port within a Device. ConsolePorts connect to ConsoleServerPorts.
     """
     """
@@ -251,7 +255,7 @@ class ConsolePort(CableTermination, PathEndpoint, ComponentModel):
 #
 #
 
 
 @extras_features('custom_fields', 'export_templates', 'webhooks')
 @extras_features('custom_fields', 'export_templates', 'webhooks')
-class ConsoleServerPort(CableTermination, PathEndpoint, ComponentModel):
+class ConsoleServerPort(ComponentModel, CableTermination, PathEndpoint):
     """
     """
     A physical port within a Device (typically a designated console server) which provides access to ConsolePorts.
     A physical port within a Device (typically a designated console server) which provides access to ConsolePorts.
     """
     """
@@ -295,7 +299,7 @@ class ConsoleServerPort(CableTermination, PathEndpoint, ComponentModel):
 #
 #
 
 
 @extras_features('custom_fields', 'export_templates', 'webhooks')
 @extras_features('custom_fields', 'export_templates', 'webhooks')
-class PowerPort(CableTermination, PathEndpoint, ComponentModel):
+class PowerPort(ComponentModel, CableTermination, PathEndpoint):
     """
     """
     A physical power supply (intake) port within a Device. PowerPorts connect to PowerOutlets.
     A physical power supply (intake) port within a Device. PowerPorts connect to PowerOutlets.
     """
     """
@@ -407,7 +411,7 @@ class PowerPort(CableTermination, PathEndpoint, ComponentModel):
 #
 #
 
 
 @extras_features('custom_fields', 'export_templates', 'webhooks')
 @extras_features('custom_fields', 'export_templates', 'webhooks')
-class PowerOutlet(CableTermination, PathEndpoint, ComponentModel):
+class PowerOutlet(ComponentModel, CableTermination, PathEndpoint):
     """
     """
     A physical power outlet (output) within a Device which provides power to a PowerPort.
     A physical power outlet (output) within a Device which provides power to a PowerPort.
     """
     """
@@ -508,7 +512,7 @@ class BaseInterface(models.Model):
 
 
 
 
 @extras_features('custom_fields', 'export_templates', 'webhooks')
 @extras_features('custom_fields', 'export_templates', 'webhooks')
-class Interface(CableTermination, PathEndpoint, ComponentModel, BaseInterface):
+class Interface(ComponentModel, BaseInterface, CableTermination, PathEndpoint):
     """
     """
     A network interface within a Device. A physical Interface can connect to exactly one other Interface.
     A network interface within a Device. A physical Interface can connect to exactly one other Interface.
     """
     """
@@ -619,16 +623,12 @@ class Interface(CableTermination, PathEndpoint, ComponentModel, BaseInterface):
             raise ValidationError({'lag': "A LAG interface cannot be its own parent."})
             raise ValidationError({'lag': "A LAG interface cannot be its own parent."})
 
 
         # Validate untagged VLAN
         # Validate untagged VLAN
-        if self.untagged_vlan and self.untagged_vlan.site not in [self.parent.site, None]:
+        if self.untagged_vlan and self.untagged_vlan.site not in [self.device.site, None]:
             raise ValidationError({
             raise ValidationError({
                 'untagged_vlan': "The untagged VLAN ({}) must belong to the same site as the interface's parent "
                 'untagged_vlan': "The untagged VLAN ({}) must belong to the same site as the interface's parent "
                                  "device, or it must be global".format(self.untagged_vlan)
                                  "device, or it must be global".format(self.untagged_vlan)
             })
             })
 
 
-    @property
-    def parent(self):
-        return self.device
-
     @property
     @property
     def is_connectable(self):
     def is_connectable(self):
         return self.type not in NONCONNECTABLE_IFACE_TYPES
         return self.type not in NONCONNECTABLE_IFACE_TYPES
@@ -655,7 +655,7 @@ class Interface(CableTermination, PathEndpoint, ComponentModel, BaseInterface):
 #
 #
 
 
 @extras_features('custom_fields', 'export_templates', 'webhooks')
 @extras_features('custom_fields', 'export_templates', 'webhooks')
-class FrontPort(CableTermination, ComponentModel):
+class FrontPort(ComponentModel, CableTermination):
     """
     """
     A pass-through port on the front of a Device.
     A pass-through port on the front of a Device.
     """
     """
@@ -721,7 +721,7 @@ class FrontPort(CableTermination, ComponentModel):
 
 
 
 
 @extras_features('custom_fields', 'export_templates', 'webhooks')
 @extras_features('custom_fields', 'export_templates', 'webhooks')
-class RearPort(CableTermination, ComponentModel):
+class RearPort(ComponentModel, CableTermination):
     """
     """
     A pass-through port on the rear of a Device.
     A pass-through port on the rear of a Device.
     """
     """

+ 1 - 1
netbox/dcim/models/power.py

@@ -201,7 +201,7 @@ class PowerFeed(PrimaryModel, PathEndpoint, CableTermination):
         super().save(*args, **kwargs)
         super().save(*args, **kwargs)
 
 
     @property
     @property
-    def parent(self):
+    def parent_object(self):
         return self.power_panel
         return self.power_panel
 
 
     def get_type_class(self):
     def get_type_class(self):

+ 2 - 2
netbox/dcim/tables/template_code.py

@@ -1,6 +1,6 @@
 CABLETERMINATION = """
 CABLETERMINATION = """
 {% if value %}
 {% if value %}
-    <a href="{{ value.parent.get_absolute_url }}">{{ value.parent }}</a>
+    <a href="{{ value.parent_object.get_absolute_url }}">{{ value.parent_object }}</a>
     <i class="mdi mdi-chevron-right"></i>
     <i class="mdi mdi-chevron-right"></i>
     <a href="{{ value.get_absolute_url }}">{{ value }}</a>
     <a href="{{ value.get_absolute_url }}">{{ value }}</a>
 {% else %}
 {% else %}
@@ -64,7 +64,7 @@ POWERFEED_CABLE = """
 """
 """
 
 
 POWERFEED_CABLETERMINATION = """
 POWERFEED_CABLETERMINATION = """
-<a href="{{ value.parent.get_absolute_url }}">{{ value.parent }}</a>
+<a href="{{ value.parent_object.get_absolute_url }}">{{ value.parent_object }}</a>
 <i class="mdi mdi-chevron-right"></i>
 <i class="mdi mdi-chevron-right"></i>
 <a href="{{ value.get_absolute_url }}">{{ value }}</a>
 <a href="{{ value.get_absolute_url }}">{{ value }}</a>
 """
 """

+ 2 - 2
netbox/dcim/views.py

@@ -2178,13 +2178,13 @@ class CableCreateView(generic.ObjectEditView):
         initial_data = {k: request.GET[k] for k in request.GET}
         initial_data = {k: request.GET[k] for k in request.GET}
 
 
         # Set initial site and rack based on side A termination (if not already set)
         # Set initial site and rack based on side A termination (if not already set)
-        termination_a_site = getattr(obj.termination_a.parent, 'site', None)
+        termination_a_site = getattr(obj.termination_a.parent_object, 'site', None)
         if termination_a_site and 'termination_b_region' not in initial_data:
         if termination_a_site and 'termination_b_region' not in initial_data:
             initial_data['termination_b_region'] = termination_a_site.region
             initial_data['termination_b_region'] = termination_a_site.region
         if 'termination_b_site' not in initial_data:
         if 'termination_b_site' not in initial_data:
             initial_data['termination_b_site'] = termination_a_site
             initial_data['termination_b_site'] = termination_a_site
         if 'termination_b_rack' not in initial_data:
         if 'termination_b_rack' not in initial_data:
-            initial_data['termination_b_rack'] = getattr(obj.termination_a.parent, 'rack', None)
+            initial_data['termination_b_rack'] = getattr(obj.termination_a.parent_object, 'rack', None)
 
 
         form = self.model_form(instance=obj, initial=initial_data)
         form = self.model_form(instance=obj, initial=initial_data)
 
 

+ 2 - 2
netbox/templates/dcim/cable_trace.html

@@ -102,12 +102,12 @@
                             <tr{% if cablepath.pk == path.pk %} class="info"{% endif %}>
                             <tr{% if cablepath.pk == path.pk %} class="info"{% endif %}>
                                 <td>
                                 <td>
                                     <a href="?cablepath_id={{ cablepath.pk }}">
                                     <a href="?cablepath_id={{ cablepath.pk }}">
-                                        {{ cablepath.origin.parent }} / {{ cablepath.origin }}
+                                        {{ cablepath.origin.parent_object }} / {{ cablepath.origin }}
                                     </a>
                                     </a>
                                 </td>
                                 </td>
                                 <td>
                                 <td>
                                     {% if cablepath.destination %}
                                     {% if cablepath.destination %}
-                                        {{ cablepath.destination }} ({{ cablepath.destination.parent }})
+                                        {{ cablepath.destination }} ({{ cablepath.destination.parent_object }})
                                     {% else %}
                                     {% else %}
                                         <span class="text-muted">Incomplete</span>
                                         <span class="text-muted">Incomplete</span>
                                     {% endif %}
                                     {% endif %}

+ 5 - 5
netbox/templates/dcim/inc/cabletermination.html

@@ -1,12 +1,12 @@
 <td>
 <td>
-    {% if termination.parent.provider %}
+    {% if termination.parent_object.provider %}
         <i class="mdi mdi-lightning-bolt" title="Circuit"></i>
         <i class="mdi mdi-lightning-bolt" title="Circuit"></i>
-        <a href="{{ termination.parent.get_absolute_url }}">
-            {{ termination.parent.provider }}
-            {{ termination.parent }}
+        <a href="{{ termination.parent_object.get_absolute_url }}">
+            {{ termination.parent_object.provider }}
+            {{ termination.parent_object }}
         </a>
         </a>
     {% else %}
     {% else %}
-        <a href="{{ termination.parent.get_absolute_url }}">{{ termination.parent }}</a>
+        <a href="{{ termination.parent_object.get_absolute_url }}">{{ termination.parent_object }}</a>
     {% endif %}
     {% endif %}
 </td>
 </td>
 <td>
 <td>

+ 1 - 1
netbox/templates/dcim/inc/endpoint_connection.html

@@ -1,6 +1,6 @@
 {% if path.destination_id %}
 {% if path.destination_id %}
     {% with endpoint=path.destination %}
     {% with endpoint=path.destination %}
-        <td><a href="{{ endpoint.parent.get_absolute_url }}">{{ endpoint.parent }}</a></td>
+        <td><a href="{{ endpoint.parent_object.get_absolute_url }}">{{ endpoint.parent_object }}</a></td>
         <td><a href="{{ endpoint.get_absolute_url }}">{{ endpoint }}</a></td>
         <td><a href="{{ endpoint.get_absolute_url }}">{{ endpoint }}</a></td>
     {% endwith %}
     {% endwith %}
 {% else %}
 {% else %}