diff --git a/netbox/dcim/api/urls.py b/netbox/dcim/api/urls.py index 724e244a2..a22a661aa 100644 --- a/netbox/dcim/api/urls.py +++ b/netbox/dcim/api/urls.py @@ -61,7 +61,8 @@ urlpatterns = [ url(r'^interfaces/(?P\d+)/$', InterfaceDetailView.as_view(), name='interface_detail'), url(r'^interfaces/(?P\d+)/graphs/$', GraphListView.as_view(), {'type': GRAPH_TYPE_INTERFACE}, name='interface_graphs'), - url(r'^interface-connections/(?P\d+)/$', InterfaceConnectionView.as_view(), name='interfaceconnection'), + url(r'^interface-connections/$', InterfaceConnectionListView.as_view(), name='interfaceconnection_list'), + url(r'^interface-connections/(?P\d+)/$', InterfaceConnectionView.as_view(), name='interfaceconnection_detail'), # Miscellaneous url(r'^related-connections/$', RelatedConnectionsView.as_view(), name='related_connections'), diff --git a/netbox/dcim/api/views.py b/netbox/dcim/api/views.py index d573cddde..27b908d56 100644 --- a/netbox/dcim/api/views.py +++ b/netbox/dcim/api/views.py @@ -326,6 +326,14 @@ class InterfaceConnectionView(generics.RetrieveUpdateDestroyAPIView): queryset = InterfaceConnection.objects.all() +class InterfaceConnectionListView(generics.ListAPIView): + """ + Retrieve a list of all interface connections + """ + serializer_class = serializers.InterfaceConnectionSerializer + queryset = InterfaceConnection.objects.all() + + # # Device bays # diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 2fdbbd0a7..65a689764 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -66,6 +66,7 @@ class SiteListView(ObjectListView): queryset = Site.objects.all() filter = filters.SiteFilter table = tables.SiteTable + sorting_attribute = 'name' template_name = 'dcim/site_list.html' diff --git a/netbox/utilities/views.py b/netbox/utilities/views.py index 9b93301b0..c7d816d18 100644 --- a/netbox/utilities/views.py +++ b/netbox/utilities/views.py @@ -1,3 +1,6 @@ +from natsort import natsorted +from operator import attrgetter + from django_tables2 import RequestConfig from django.contrib import messages @@ -25,6 +28,7 @@ class ObjectListView(View): filter = None filter_form = None table = None + sorting_attribute = None edit_permissions = [] template_name = None redirect_on_single_result = True @@ -68,6 +72,10 @@ class ObjectListView(View): # Provide a hook to tweak the queryset based on the request immediately prior to rendering the object list self.queryset = self.alter_queryset(request) + # If the sorting attribute is set, sort the final result based on the provided attribute key + if self.sorting_attribute: + self.queryset = natsorted(self.queryset, key=attrgetter(self.sorting_attribute)) + # Construct the table based on the user's permissions table = self.table(self.queryset) table.model = model