From b5dfabf651e73083bea7af6203cb18856d330257 Mon Sep 17 00:00:00 2001 From: Sander Steffann Date: Wed, 23 Oct 2019 13:38:37 +0200 Subject: [PATCH] Remove ugly hacks and add property of CableTermination type --- netbox/dcim/models.py | 5 +++++ netbox/templates/dcim/inc/interface.html | 11 ++++------- netbox/templates/dcim/inc/interface_path.html | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 754fd84b7..ad0a3f9f3 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -11,6 +11,7 @@ from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models from django.db.models import Count, Q, Sum from django.urls import reverse +from django.utils.functional import cached_property from mptt.models import MPTTModel, TreeForeignKey from taggit.managers import TaggableManager from timezone_field import TimeZoneField @@ -157,6 +158,10 @@ class CableTermination(models.Model): class Meta: abstract = True + @cached_property + def termination_type(self): + return self.__class__.__name__ + def get_peer_port(self): return None diff --git a/netbox/templates/dcim/inc/interface.html b/netbox/templates/dcim/inc/interface.html index 55f6aa4a8..ff4662981 100644 --- a/netbox/templates/dcim/inc/interface.html +++ b/netbox/templates/dcim/inc/interface.html @@ -74,8 +74,7 @@ Wireless interface {% elif iface.connected_endpoint %} {% with endpoint=iface.connected_endpoint previous_endpoint=iface.via_endpoints|last %} - {% if endpoint.positions and previous_endpoint.rear_port_position %} - {# RearPort has positions, FrontPort has rear port position #} + {% if endpoint.termination_type == 'RearPort' and previous_endpoint.termination_type == 'FrontPort' %} {# Ending at a rear port isn't interesting if we know the front port #} @@ -90,8 +89,7 @@ {{ previous_endpoint.name }} - {% elif endpoint.name and endpoint.device %} - {# Interface, FrontPort and RearPort have a name and a device #} + {% elif endpoint.termination_type in 'Interface,FrontPort,RearPort' %} {{ endpoint.device }} @@ -101,7 +99,7 @@ {% endwith %} - {% if endpoint.get_type_display %} + {% if endpoint.termination_type == 'Interface' %} {{ endpoint.name }} @@ -113,8 +111,7 @@ {% endif %} - {% elif endpoint.circuit %} - {# CircuitTermination has a circuit #} + {% elif endpoint.termination_type == 'CircuitTermination' %} {% if endpoint.circuit == previous_endpoint.circuit %} {# We have the remote endpoint, show the remote site #} diff --git a/netbox/templates/dcim/inc/interface_path.html b/netbox/templates/dcim/inc/interface_path.html index 063f6b030..75ad8f395 100644 --- a/netbox/templates/dcim/inc/interface_path.html +++ b/netbox/templates/dcim/inc/interface_path.html @@ -4,16 +4,16 @@ via {% for endpoint in path %} {% ifchanged %} - {% if endpoint.positions %} + {% if endpoint.termination_type == 'RearPort' %} {# Don't show RearPort #} - {% elif endpoint.rear_port_position %} + {% elif endpoint.termination_type == 'FrontPort' %} {{ endpoint.device }} {{ endpoint.name }} - {% elif endpoint.circuit %} + {% elif endpoint.termination_type == 'CircuitTermination' %} {{ endpoint.circuit }}