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

Fixes #8187: Fix rendering of tags column in object tables

jeremystretch 4 лет назад
Родитель
Сommit
6cda55da06
3 измененных файлов с 42 добавлено и 1 удалено
  1. 4 0
      docs/release-notes/version-3.1.md
  2. 2 1
      netbox/utilities/tables.py
  3. 36 0
      netbox/utilities/tests/test_tables.py

+ 4 - 0
docs/release-notes/version-3.1.md

@@ -2,6 +2,10 @@
 
 
 ## v3.1.4 (FUTURE)
 ## v3.1.4 (FUTURE)
 
 
+### Bug Fixes
+
+* [#8187](https://github.com/netbox-community/netbox/issues/8187) - Fix rendering of tags column in object tables
+
 ---
 ---
 
 
 ## v3.1.3 (2021-12-29)
 ## v3.1.3 (2021-12-29)

+ 2 - 1
netbox/utilities/tables.py

@@ -381,8 +381,9 @@ class TagColumn(tables.TemplateColumn):
     Display a list of tags assigned to the object.
     Display a list of tags assigned to the object.
     """
     """
     template_code = """
     template_code = """
+    {% load helpers %}
     {% for tag in value.all %}
     {% for tag in value.all %}
-        {% include 'utilities/templatetags/tag.html' %}
+        {% tag tag url_name=url_name %}
     {% empty %}
     {% empty %}
         <span class="text-muted">&mdash;</span>
         <span class="text-muted">&mdash;</span>
     {% endfor %}
     {% endfor %}

+ 36 - 0
netbox/utilities/tests/test_tables.py

@@ -0,0 +1,36 @@
+from django.template import Context, Template
+from django.test import TestCase
+
+from dcim.models import Site
+from utilities.tables import BaseTable, TagColumn
+from utilities.testing import create_tags
+
+
+class TagColumnTable(BaseTable):
+    tags = TagColumn(url_name='dcim:site_list')
+
+    class Meta(BaseTable.Meta):
+        model = Site
+        fields = ('pk', 'name', 'tags',)
+        default_columns = fields
+
+
+class TagColumnTest(TestCase):
+
+    @classmethod
+    def setUpTestData(cls):
+        tags = create_tags('Alpha', 'Bravo', 'Charlie')
+
+        sites = [
+            Site(name=f'Site {i}', slug=f'site-{i}') for i in range(1, 6)
+        ]
+        Site.objects.bulk_create(sites)
+        for site in sites:
+            site.tags.add(*tags)
+
+    def test_tagcolumn(self):
+        template = Template('{% load render_table from django_tables2 %}{% render_table table %}')
+        context = Context({
+            'table': TagColumnTable(Site.objects.all(), orderable=False)
+        })
+        template.render(context)