Browse Source

Closes #6038: Include tagged objects list on tag view

Jeremy Stretch 4 years ago
parent
commit
c7040fd418

+ 1 - 0
docs/release-notes/version-2.11.md

@@ -99,6 +99,7 @@ A new Cloud model has been introduced to represent the boundary of a network tha
 * [#5971](https://github.com/netbox-community/netbox/issues/5971) - Add dedicated views for organizational models
 * [#5972](https://github.com/netbox-community/netbox/issues/5972) - Enable bulk editing for organizational models
 * [#5975](https://github.com/netbox-community/netbox/issues/5975) - Allow partial (decimal) vCPU allocations for virtual machines
+* [#6038](https://github.com/netbox-community/netbox/issues/6038) - Include tagged objects list on tag view
 
 ### Other Changes
 

+ 6 - 14
netbox/extras/tables.py

@@ -6,14 +6,6 @@ from utilities.tables import (
 )
 from .models import ConfigContext, JournalEntry, ObjectChange, Tag, TaggedItem
 
-TAGGED_ITEM = """
-{% if value.get_absolute_url %}
-    <a href="{{ value.get_absolute_url }}">{{ value }}</a>
-{% else %}
-    {{ value }}
-{% endif %}
-"""
-
 CONFIGCONTEXT_ACTIONS = """
 {% if perms.extras.change_configcontext %}
     <a href="{% url 'extras:configcontext_edit' pk=record.pk %}" class="btn btn-xs btn-warning"><i class="mdi mdi-pencil" aria-hidden="true"></i></a>
@@ -50,18 +42,18 @@ class TagTable(BaseTable):
 
 
 class TaggedItemTable(BaseTable):
-    content_object = tables.TemplateColumn(
-        template_code=TAGGED_ITEM,
+    content_type = ContentTypeColumn(
+        verbose_name='Type'
+    )
+    content_object = tables.Column(
+        linkify=True,
         orderable=False,
         verbose_name='Object'
     )
-    content_type = tables.Column(
-        verbose_name='Type'
-    )
 
     class Meta(BaseTable.Meta):
         model = TaggedItem
-        fields = ('content_object', 'content_type')
+        fields = ('content_type', 'content_object')
 
 
 class ConfigContextTable(BaseTable):

+ 6 - 0
netbox/extras/views.py

@@ -39,8 +39,14 @@ class TagView(generic.ObjectView):
 
     def get_extra_context(self, request, instance):
         tagged_items = TaggedItem.objects.filter(tag=instance)
+        taggeditem_table = tables.TaggedItemTable(
+            data=tagged_items,
+            orderable=False
+        )
+        paginate_table(taggeditem_table, request)
 
         return {
+            'taggeditem_table': taggeditem_table,
             'tagged_item_count': tagged_items.count(),
         }
 

+ 9 - 2
netbox/templates/extras/tag.html

@@ -32,7 +32,7 @@
         <tr>
           <td>Tagged Items</td>
           <td>
-            {{ tagged_item_count }}
+            {{ taggeditem_table.rows|length }}
           </td>
         </tr>
       </table>
@@ -45,7 +45,14 @@
 </div>
 <div class="row">
 	<div class="col-md-12">
-      {% plugin_full_width_page object %}
+    <div class="panel panel-default">
+      <div class="panel-heading">
+        <strong>Device Types</strong>
+      </div>
+      {% include 'inc/table.html' with table=taggeditem_table %}
+    </div>
+    {% include 'inc/paginator.html' with paginator=taggeditem_table.paginator page=taggeditem_table.page %}
+    {% plugin_full_width_page object %}
   </div>
 </div>
 {% endblock %}