Просмотр исходного кода

Added tags panel to object list view

Jeremy Stretch 7 лет назад
Родитель
Сommit
1d1553275e

+ 1 - 0
netbox/templates/circuits/circuit_list.html

@@ -16,6 +16,7 @@
     </div>
     </div>
     <div class="col-md-3">
     <div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
     </div>
     </div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/circuits/provider_list.html

@@ -16,6 +16,7 @@
     </div>
     </div>
     <div class="col-md-3">
     <div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
     </div>
     </div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/dcim/device_list.html

@@ -16,6 +16,7 @@
     </div>
     </div>
     <div class="col-md-3">
     <div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
     </div>
     </div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/dcim/devicetype_list.html

@@ -16,6 +16,7 @@
     </div>
     </div>
     <div class="col-md-3">
     <div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
     </div>
     </div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/dcim/rack_list.html

@@ -16,6 +16,7 @@
     </div>
     </div>
     <div class="col-md-3">
     <div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
     </div>
     </div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/dcim/site_list.html

@@ -16,6 +16,7 @@
     </div>
     </div>
     <div class="col-md-3">
     <div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
     </div>
     </div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 13 - 0
netbox/templates/inc/tags_panel.html

@@ -0,0 +1,13 @@
+{% load helpers %}
+
+<div class="panel panel-default">
+    <div class="panel-heading">
+        <span class="fa fa-tags" aria-hidden="true"></span>
+        <strong>Tags</strong>
+    </div>
+    <div class="panel-body text-center">
+        {% for tag in tags %}
+            <a href="{% querystring request tag=tag.slug %}" class="btn btn-sm btn-default">{{ tag }} <span class="badge">{{ tag.count }}</span></a>
+        {% endfor %}
+    </div>
+</div>

+ 1 - 0
netbox/templates/ipam/aggregate_list.html

@@ -17,6 +17,7 @@
 	</div>
 	</div>
 	<div class="col-md-3">
 	<div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
         <div class="panel panel-default">
         <div class="panel panel-default">
             <div class="panel-heading">
             <div class="panel-heading">
                 <strong><i class="fa fa-bar-chart"></i> Statistics</strong>
                 <strong><i class="fa fa-bar-chart"></i> Statistics</strong>

+ 1 - 0
netbox/templates/ipam/ipaddress_list.html

@@ -16,6 +16,7 @@
 	</div>
 	</div>
 	<div class="col-md-3">
 	<div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
 	</div>
 	</div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/ipam/prefix_list.html

@@ -21,6 +21,7 @@
 	</div>
 	</div>
 	<div class="col-md-3">
 	<div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
 	</div>
 	</div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/ipam/vlan_list.html

@@ -16,6 +16,7 @@
 	</div>
 	</div>
 	<div class="col-md-3">
 	<div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
 	</div>
 	</div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/ipam/vrf_list.html

@@ -16,6 +16,7 @@
 	</div>
 	</div>
 	<div class="col-md-3">
 	<div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
 	</div>
 	</div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/secrets/secret_list.html

@@ -14,6 +14,7 @@
     </div>
     </div>
     <div class="col-md-3">
     <div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
     </div>
     </div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/tenancy/tenant_list.html

@@ -16,6 +16,7 @@
     </div>
     </div>
     <div class="col-md-3">
     <div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
     </div>
     </div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/virtualization/cluster_list.html

@@ -16,6 +16,7 @@
     </div>
     </div>
     <div class="col-md-3">
     <div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
     </div>
     </div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 1 - 0
netbox/templates/virtualization/virtualmachine_list.html

@@ -16,6 +16,7 @@
     </div>
     </div>
     <div class="col-md-3">
     <div class="col-md-3">
 		{% include 'inc/search_panel.html' %}
 		{% include 'inc/search_panel.html' %}
+		{% include 'inc/tags_panel.html' %}
     </div>
     </div>
 </div>
 </div>
 {% endblock %}
 {% endblock %}

+ 8 - 1
netbox/utilities/views.py

@@ -8,7 +8,7 @@ from django.contrib import messages
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.contenttypes.models import ContentType
 from django.core.exceptions import ValidationError
 from django.core.exceptions import ValidationError
 from django.db import transaction, IntegrityError
 from django.db import transaction, IntegrityError
-from django.db.models import ProtectedError
+from django.db.models import Count, ProtectedError
 from django.forms import CharField, Form, ModelMultipleChoiceField, MultipleHiddenInput, Textarea
 from django.forms import CharField, Form, ModelMultipleChoiceField, MultipleHiddenInput, Textarea
 from django.shortcuts import get_object_or_404, redirect, render
 from django.shortcuts import get_object_or_404, redirect, render
 from django.template.exceptions import TemplateSyntaxError
 from django.template.exceptions import TemplateSyntaxError
@@ -119,6 +119,12 @@ class ObjectListView(View):
         if 'pk' in table.base_columns and (permissions['change'] or permissions['delete']):
         if 'pk' in table.base_columns and (permissions['change'] or permissions['delete']):
             table.columns.show('pk')
             table.columns.show('pk')
 
 
+        # Construct queryset for tags list
+        if hasattr(model, 'tags'):
+            tags = model.tags.annotate(count=Count('taggit_taggeditem_items'))
+        else:
+            tags = None
+
         # Apply the request context
         # Apply the request context
         paginate = {
         paginate = {
             'klass': EnhancedPaginator,
             'klass': EnhancedPaginator,
@@ -131,6 +137,7 @@ class ObjectListView(View):
             'table': table,
             'table': table,
             'permissions': permissions,
             'permissions': permissions,
             'filter_form': self.filter_form(request.GET, label_suffix='') if self.filter_form else None,
             'filter_form': self.filter_form(request.GET, label_suffix='') if self.filter_form else None,
+            'tags': tags,
         }
         }
         context.update(self.extra_context())
         context.update(self.extra_context())