diff --git a/conntrackt/admin.py b/conntrackt/admin.py --- a/conntrackt/admin.py +++ b/conntrackt/admin.py @@ -40,6 +40,10 @@ # +# Standard library imports. +from urlparse import parse_qsl + + # Django imports. from django.contrib import admin from django.urls import resolve @@ -230,22 +234,22 @@ class CommunicationAdmin(admin.ModelAdmi kwargs - Additional keyword arguments """ - # Resolve the view name based on the request's path. - view_name = resolve(request.path).view_name - # Only process the source and destination fields that point to # interfaces. if db_field.name == "source" or db_field.name == "destination": # Perform no filtering by default. interface_filter = {} - # If project was specified in GET requests, add it as a filter. - if 'project' in request.GET: - interface_filter['entity__project'] = request.GET['project'] - # If location was specified in GET request, add it as a filter. - if 'location' in request.GET: - interface_filter['entity__location'] = request.GET['location'] - # If there are any filtering options for the show interfaces, apply them. + # Parse the filter from URL GET parameter passed-in by the Django Admin. + changelist_filters = dict(parse_qsl(request.GET.get('_changelist_filters', ''))) + + # Apply project filter if requested. + if 'project' in changelist_filters: + interface_filter['entity__project'] = changelist_filters['project'] + # Apply location filter if requested. + if 'location' in changelist_filters: + interface_filter['entity__location'] = changelist_filters['location'] + # Apply our filters to queryset if there are any. if interface_filter: kwargs["queryset"] = Interface.objects.filter(**interface_filter) diff --git a/conntrackt/templates/admin/conntrackt/communication/change_list.html b/conntrackt/templates/admin/conntrackt/communication/change_list.html deleted file mode 100644 --- a/conntrackt/templates/admin/conntrackt/communication/change_list.html +++ /dev/null @@ -1,16 +0,0 @@ -{% extends "admin/change_list.html" %} -{% load i18n admin_static admin_list %} -{% load admin_urls %} - -{% block object-tools-items %} - {% if has_add_permission %} -
  • - {# Add the GET parameters from the admin's filter to 'Add entity' button #} - {# so we can perform some filtering on source/destination interfaces. #} - - {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %} - -
  • - {% endif %} -{% endblock %} -