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.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

View File

@ -74,8 +74,7 @@
<td colspan="2" class="text-muted">Wireless interface</td>
{% 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 #}
<td>
<a href="{% url 'dcim:device' pk=previous_endpoint.device.pk %}">
@ -90,8 +89,7 @@
{{ previous_endpoint.name }}
</a>
</td>
{% elif endpoint.name and endpoint.device %}
{# Interface, FrontPort and RearPort have a name and a device #}
{% elif endpoint.termination_type in 'Interface,FrontPort,RearPort' %}
<td>
<a href="{% url 'dcim:device' pk=endpoint.device.pk %}">
{{ endpoint.device }}
@ -101,7 +99,7 @@
{% endwith %}
</td>
<td>
{% if endpoint.get_type_display %}
{% if endpoint.termination_type == 'Interface' %}
<a href="{% url 'dcim:interface' pk=endpoint.pk %}">
<span title="{{ endpoint.get_type_display }}">
{{ endpoint.name }}
@ -113,8 +111,7 @@
</a>
{% endif %}
</td>
{% elif endpoint.circuit %}
{# CircuitTermination has a circuit #}
{% elif endpoint.termination_type == 'CircuitTermination' %}
<td colspan="2">
{% if endpoint.circuit == previous_endpoint.circuit %}
{# We have the remote endpoint, show the remote site #}

View File

@ -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' %}
<span class="path-element">
<a href="{% url 'dcim:device' pk=endpoint.device.pk %}">
{{ endpoint.device }}
</a>
{{ endpoint.name }}
</span>
{% elif endpoint.circuit %}
{% elif endpoint.termination_type == 'CircuitTermination' %}
<span class="path-element">
<a href="{% url 'circuits:circuit' pk=endpoint.circuit.pk %}">
{{ endpoint.circuit }}