From a9930bd4421c353b874f6853fb8c4664b47d8f89 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 21 Jul 2021 14:11:42 -0400 Subject: [PATCH] Optimize display of ConfigContext assigned objects --- netbox/extras/views.py | 16 +++ netbox/templates/extras/configcontext.html | 136 ++------------------- 2 files changed, 28 insertions(+), 124 deletions(-) diff --git a/netbox/extras/views.py b/netbox/extras/views.py index 10bf2f6c8..b23dc0230 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -276,6 +276,21 @@ class ConfigContextView(generic.ObjectView): queryset = ConfigContext.objects.all() def get_extra_context(self, request, instance): + # Gather assigned objects for parsing in the template + assigned_objects = ( + ('Regions', instance.regions.all), + ('Site Groups', instance.site_groups.all), + ('Sites', instance.sites.all), + ('Device Types', instance.device_types.all), + ('Roles', instance.roles.all), + ('Platforms', instance.platforms.all), + ('Cluster Groups', instance.cluster_groups.all), + ('Clusters', instance.clusters.all), + ('Tenant Groups', instance.tenant_groups.all), + ('Tenants', instance.tenants.all), + ('Tags', instance.tags.all), + ) + # Determine user's preferred output format if request.GET.get('format') in ['json', 'yaml']: format = request.GET.get('format') @@ -287,6 +302,7 @@ class ConfigContextView(generic.ObjectView): format = 'json' return { + 'assigned_objects': assigned_objects, 'format': format, } diff --git a/netbox/templates/extras/configcontext.html b/netbox/templates/extras/configcontext.html index 0b6cc9eab..3a9cc2e0c 100644 --- a/netbox/templates/extras/configcontext.html +++ b/netbox/templates/extras/configcontext.html @@ -50,132 +50,20 @@
+ {% for title, objects in assigned_objects %} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + {% endfor %}
Regions - {% if object.regions.all %} -
    - {% for region in object.regions.all %} -
  • {{ region }}
  • - {% endfor %} -
- {% else %} - None - {% endif %} -
Sites - {% if object.sites.all %} -
    - {% for site in object.sites.all %} -
  • {{ site }}
  • - {% endfor %} -
- {% else %} - None - {% endif %} -
Roles - {% if object.roles.all %} -
    - {% for role in object.roles.all %} -
  • {{ role }}
  • - {% endfor %} -
- {% else %} - None - {% endif %} -
Platforms - {% if object.platforms.all %} -
    - {% for platform in object.platforms.all %} -
  • {{ platform }}
  • - {% endfor %} -
- {% else %} - None - {% endif %} -
Cluster Groups - {% if object.cluster_groups.all %} -
    - {% for cluster_group in object.cluster_groups.all %} -
  • {{ cluster_group }}
  • - {% endfor %} -
- {% else %} - None - {% endif %} -
Clusters - {% if object.clusters.all %} -
    - {% for cluster in object.clusters.all %} -
  • {{ cluster }}
  • - {% endfor %} -
- {% else %} - None - {% endif %} -
Tenant Groups - {% if object.tenant_groups.all %} -
    - {% for tenant_group in object.tenant_groups.all %} -
  • {{ tenant_group }}
  • - {% endfor %} -
- {% else %} - None - {% endif %} -
Tenants - {% if object.tenants.all %} -
    - {% for tenant in object.tenants.all %} -
  • {{ tenant }}
  • - {% endfor %} -
- {% else %} - None - {% endif %} -
Tags - {% if object.tags.all %} -
    - {% for tag in object.tags.all %} -
  • {{ tag }}
  • - {% endfor %} -
- {% else %} - None - {% endif %} -
{{ title }} +
    + {% for object in objects %} +
  • {{ object }}
  • + {% empty %} +
  • None
  • + {% endfor %} +
+