Remove ugly hacks and add property of CableTermination type

This commit is contained in:
Sander Steffann 2019-10-23 13:38:37 +02:00
parent b8f8ae4a58
commit b5dfabf651
3 changed files with 12 additions and 10 deletions

View File

@ -11,6 +11,7 @@ from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models from django.db import models
from django.db.models import Count, Q, Sum from django.db.models import Count, Q, Sum
from django.urls import reverse from django.urls import reverse
from django.utils.functional import cached_property
from mptt.models import MPTTModel, TreeForeignKey from mptt.models import MPTTModel, TreeForeignKey
from taggit.managers import TaggableManager from taggit.managers import TaggableManager
from timezone_field import TimeZoneField from timezone_field import TimeZoneField
@ -157,6 +158,10 @@ class CableTermination(models.Model):
class Meta: class Meta:
abstract = True abstract = True
@cached_property
def termination_type(self):
return self.__class__.__name__
def get_peer_port(self): def get_peer_port(self):
return None return None

View File

@ -74,8 +74,7 @@
<td colspan="2" class="text-muted">Wireless interface</td> <td colspan="2" class="text-muted">Wireless interface</td>
{% elif iface.connected_endpoint %} {% elif iface.connected_endpoint %}
{% with endpoint=iface.connected_endpoint previous_endpoint=iface.via_endpoints|last %} {% with endpoint=iface.connected_endpoint previous_endpoint=iface.via_endpoints|last %}
{% if endpoint.positions and previous_endpoint.rear_port_position %} {% if endpoint.termination_type == 'RearPort' and previous_endpoint.termination_type == 'FrontPort' %}
{# RearPort has positions, FrontPort has rear port position #}
{# Ending at a rear port isn't interesting if we know the front port #} {# Ending at a rear port isn't interesting if we know the front port #}
<td> <td>
<a href="{% url 'dcim:device' pk=previous_endpoint.device.pk %}"> <a href="{% url 'dcim:device' pk=previous_endpoint.device.pk %}">
@ -90,8 +89,7 @@
{{ previous_endpoint.name }} {{ previous_endpoint.name }}
</a> </a>
</td> </td>
{% elif endpoint.name and endpoint.device %} {% elif endpoint.termination_type in 'Interface,FrontPort,RearPort' %}
{# Interface, FrontPort and RearPort have a name and a device #}
<td> <td>
<a href="{% url 'dcim:device' pk=endpoint.device.pk %}"> <a href="{% url 'dcim:device' pk=endpoint.device.pk %}">
{{ endpoint.device }} {{ endpoint.device }}
@ -101,7 +99,7 @@
{% endwith %} {% endwith %}
</td> </td>
<td> <td>
{% if endpoint.get_type_display %} {% if endpoint.termination_type == 'Interface' %}
<a href="{% url 'dcim:interface' pk=endpoint.pk %}"> <a href="{% url 'dcim:interface' pk=endpoint.pk %}">
<span title="{{ endpoint.get_type_display }}"> <span title="{{ endpoint.get_type_display }}">
{{ endpoint.name }} {{ endpoint.name }}
@ -113,8 +111,7 @@
</a> </a>
{% endif %} {% endif %}
</td> </td>
{% elif endpoint.circuit %} {% elif endpoint.termination_type == 'CircuitTermination' %}
{# CircuitTermination has a circuit #}
<td colspan="2"> <td colspan="2">
{% if endpoint.circuit == previous_endpoint.circuit %} {% if endpoint.circuit == previous_endpoint.circuit %}
{# We have the remote endpoint, show the remote site #} {# We have the remote endpoint, show the remote site #}

View File

@ -4,16 +4,16 @@
via via
{% for endpoint in path %} {% for endpoint in path %}
{% ifchanged %} {% ifchanged %}
{% if endpoint.positions %} {% if endpoint.termination_type == 'RearPort' %}
{# Don't show RearPort #} {# Don't show RearPort #}
{% elif endpoint.rear_port_position %} {% elif endpoint.termination_type == 'FrontPort' %}
<span class="path-element"> <span class="path-element">
<a href="{% url 'dcim:device' pk=endpoint.device.pk %}"> <a href="{% url 'dcim:device' pk=endpoint.device.pk %}">
{{ endpoint.device }} {{ endpoint.device }}
</a> </a>
{{ endpoint.name }} {{ endpoint.name }}
</span> </span>
{% elif endpoint.circuit %} {% elif endpoint.termination_type == 'CircuitTermination' %}
<span class="path-element"> <span class="path-element">
<a href="{% url 'circuits:circuit' pk=endpoint.circuit.pk %}"> <a href="{% url 'circuits:circuit' pk=endpoint.circuit.pk %}">
{{ endpoint.circuit }} {{ endpoint.circuit }}