Fixed cable list display for circuit terminations

This commit is contained in:
Jeremy Stretch 2018-11-01 14:14:31 -04:00
parent 1119209fa0
commit 623de7d210
4 changed files with 27 additions and 18 deletions

View File

@ -264,7 +264,7 @@ class CircuitTermination(CableTermination):
unique_together = ['circuit', 'term_side']
def __str__(self):
return '{} (Side {})'.format(self.circuit, self.get_term_side_display())
return 'Side {}'.format(self.get_term_side_display())
def log_change(self, user, request_id, action):
"""

View File

@ -498,7 +498,9 @@ class InterfaceConnectionViewSet(ModelViewSet):
#
class CableViewSet(ModelViewSet):
queryset = Cable.objects.prefetch_related('termination_a__device', 'termination_b__device')
queryset = Cable.objects.prefetch_related(
'termination_a', 'termination_b'
)
serializer_class = serializers.CableSerializer
filter_class = filters.CableFilter

View File

@ -170,6 +170,14 @@ VIRTUALCHASSIS_ACTIONS = """
{% endif %}
"""
CABLE_TERMINATION_PARENT = """
{% if value.device %}
<a href="{{ value.device.get_absolute_url }}">{{ value.device }}</a>
{% else %}
<a href="{{ value.circuit.get_absolute_url }}">{{ value.circuit }}</a>
{% endif %}
"""
CABLE_LENGTH = """
{% if record.length %}{{ record.length }}{{ record.length_unit }}{% else %}&mdash;{% endif %}
"""
@ -632,29 +640,27 @@ class CableTable(BaseTable):
accessor=Accessor('label'),
verbose_name='Label'
)
device_a = tables.LinkColumn(
viewname='dcim:device',
accessor=Accessor('termination_a.device'),
args=[Accessor('termination_a.device.pk')],
termination_a_parent = tables.TemplateColumn(
template_code=CABLE_TERMINATION_PARENT,
accessor=Accessor('termination_a'),
orderable=False,
verbose_name='Device A'
verbose_name='Termination A'
)
termination_a = tables.Column(
accessor=Accessor('termination_a.name'),
accessor=Accessor('termination_a'),
orderable=False,
verbose_name='Component'
verbose_name=''
)
device_b = tables.LinkColumn(
viewname='dcim:device',
accessor=Accessor('termination_b.device'),
args=[Accessor('termination_b.device.pk')],
termination_b_parent = tables.TemplateColumn(
template_code=CABLE_TERMINATION_PARENT,
accessor=Accessor('termination_b'),
orderable=False,
verbose_name='Device B'
verbose_name='Termination B'
)
termination_b = tables.Column(
accessor=Accessor('termination_b.name'),
accessor=Accessor('termination_b'),
orderable=False,
verbose_name='Component'
verbose_name=''
)
length = tables.TemplateColumn(
template_code=CABLE_LENGTH,
@ -665,7 +671,8 @@ class CableTable(BaseTable):
class Meta(BaseTable.Meta):
model = Cable
fields = (
'pk', 'id', 'label_', 'device_a', 'termination_a', 'device_b', 'termination_b', 'status', 'type', 'color',
'pk', 'id', 'label_', 'termination_a_parent', 'termination_a', 'termination_b_parent', 'termination_b',
'status', 'type', 'color', 'length',
)

View File

@ -1612,7 +1612,7 @@ class DeviceBulkAddDeviceBayView(PermissionRequiredMixin, BulkComponentCreateVie
class CableListView(ObjectListView):
queryset = Cable.objects.prefetch_related(
'termination_a__device', 'termination_b__device'
'termination_a', 'termination_b'
)
filter = filters.CableFilter
filter_form = forms.CableFilterForm