Skip to content

Commit

Permalink
Closes #984: Allow ordering circuits by A/Z side
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Jun 27, 2019
1 parent 2bb9464 commit 6c3c6fb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v2.6.2 (FUTURE)

## Enhancements

* [#984](https://github.com/digitalocean/netbox/issues/984) - Allow ordering circuits by A/Z side

---

v2.6.1 (2019-06-25)

## Enhancements
Expand Down
19 changes: 7 additions & 12 deletions netbox/circuits/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
"""


class CircuitTerminationColumn(tables.Column):

def render(self, value):
return mark_safe('<a href="{}">{}</a>'.format(
value.site.get_absolute_url(),
value.site
))


#
# Providers
#
Expand Down Expand Up @@ -77,9 +68,13 @@ class CircuitTable(BaseTable):
provider = tables.LinkColumn('circuits:provider', args=[Accessor('provider.slug')])
status = tables.TemplateColumn(template_code=STATUS_LABEL, verbose_name='Status')
tenant = tables.TemplateColumn(template_code=COL_TENANT)
termination_a = CircuitTerminationColumn(orderable=False, verbose_name='A Side')
termination_z = CircuitTerminationColumn(orderable=False, verbose_name='Z Side')
a_side = tables.Column(
verbose_name='A Side'
)
z_side = tables.Column(
verbose_name='Z Side'
)

class Meta(BaseTable.Meta):
model = Circuit
fields = ('pk', 'cid', 'status', 'type', 'provider', 'tenant', 'termination_a', 'termination_z', 'description')
fields = ('pk', 'cid', 'status', 'type', 'provider', 'tenant', 'a_side', 'z_side', 'description')
8 changes: 5 additions & 3 deletions netbox/circuits/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db import transaction
from django.db.models import Count
from django.db.models import Count, OuterRef, Subquery
from django.shortcuts import get_object_or_404, redirect, render
from django.utils.decorators import method_decorator
from django.views.generic import View

from extras.models import Graph, GRAPH_TYPE_PROVIDER
Expand Down Expand Up @@ -135,10 +133,14 @@ class CircuitTypeBulkDeleteView(PermissionRequiredMixin, BulkDeleteView):

class CircuitListView(PermissionRequiredMixin, ObjectListView):
permission_required = 'circuits.view_circuit'
_terminations = CircuitTermination.objects.filter(circuit=OuterRef('pk'))
queryset = Circuit.objects.select_related(
'provider', 'type', 'tenant'
).prefetch_related(
'terminations__site'
).annotate(
a_side=Subquery(_terminations.filter(term_side='A').values('site__name')[:1]),
z_side=Subquery(_terminations.filter(term_side='Z').values('site__name')[:1]),
)
filter = filters.CircuitFilter
filter_form = forms.CircuitFilterForm
Expand Down

0 comments on commit 6c3c6fb

Please sign in to comment.