1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Rename parent attribute on CableTerminations to parent_object

This commit is contained in:
Jeremy Stretch
2021-03-05 13:06:21 -05:00
parent 7a5cf80412
commit 8e1fe6339e
8 changed files with 28 additions and 28 deletions

View File

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

View File

@ -84,8 +84,8 @@ class ComponentModel(PrimaryModel):
return super().to_objectchange(action, related_object=device)
@property
def parent(self):
return getattr(self, 'device', None)
def parent_object(self):
return self.device
class CableTermination(models.Model):
@ -152,6 +152,10 @@ class CableTermination(models.Model):
def _occupied(self):
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):
"""
@ -207,7 +211,7 @@ class PathEndpoint(models.Model):
#
@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.
"""
@ -251,7 +255,7 @@ class ConsolePort(CableTermination, PathEndpoint, ComponentModel):
#
@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.
"""
@ -295,7 +299,7 @@ class ConsoleServerPort(CableTermination, PathEndpoint, ComponentModel):
#
@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.
"""
@ -407,7 +411,7 @@ class PowerPort(CableTermination, PathEndpoint, ComponentModel):
#
@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.
"""
@ -508,7 +512,7 @@ class BaseInterface(models.Model):
@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.
"""
@ -619,16 +623,12 @@ class Interface(CableTermination, PathEndpoint, ComponentModel, BaseInterface):
raise ValidationError({'lag': "A LAG interface cannot be its own parent."})
# 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({
'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)
})
@property
def parent(self):
return self.device
@property
def is_connectable(self):
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')
class FrontPort(CableTermination, ComponentModel):
class FrontPort(ComponentModel, CableTermination):
"""
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')
class RearPort(CableTermination, ComponentModel):
class RearPort(ComponentModel, CableTermination):
"""
A pass-through port on the rear of a Device.
"""

View File

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

View File

@ -1,6 +1,6 @@
CABLETERMINATION = """
{% 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>
<a href="{{ value.get_absolute_url }}">{{ value }}</a>
{% else %}
@ -64,7 +64,7 @@ POWERFEED_CABLE = """
"""
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>
<a href="{{ value.get_absolute_url }}">{{ value }}</a>
"""

View File

@ -2178,13 +2178,13 @@ class CableCreateView(generic.ObjectEditView):
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)
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:
initial_data['termination_b_region'] = termination_a_site.region
if 'termination_b_site' not in initial_data:
initial_data['termination_b_site'] = termination_a_site
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)

View File

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

View File

@ -1,12 +1,12 @@
<td>
{% if termination.parent.provider %}
{% if termination.parent_object.provider %}
<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>
{% else %}
<a href="{{ termination.parent.get_absolute_url }}">{{ termination.parent }}</a>
<a href="{{ termination.parent_object.get_absolute_url }}">{{ termination.parent_object }}</a>
{% endif %}
</td>
<td>

View File

@ -1,6 +1,6 @@
{% if path.destination_id %}
{% 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>
{% endwith %}
{% else %}