Kaynağa Gözat

Return a plain string from Prefix.get_classification_display()

Resolve the lazy translation label with force_str(), as Django's own
get_FOO_display() does, so table cell values and exports receive a str.
Jeremy Stretch 2 gün önce
ebeveyn
işleme
e963296bc9

+ 2 - 1
netbox/ipam/models/ip.py

@@ -6,6 +6,7 @@ from django.core.exceptions import ValidationError
 from django.db import models
 from django.db import models
 from django.db.models import F
 from django.db.models import F
 from django.db.models.functions import Cast
 from django.db.models.functions import Cast
+from django.utils.encoding import force_str
 from django.utils.functional import cached_property
 from django.utils.functional import cached_property
 from django.utils.translation import gettext_lazy as _
 from django.utils.translation import gettext_lazy as _
 
 
@@ -405,7 +406,7 @@ class Prefix(ContactsMixin, GetAvailablePrefixesMixin, CachedScopeMixin, Primary
         return PrefixClassificationChoices.colors.get(self.classification)
         return PrefixClassificationChoices.colors.get(self.classification)
 
 
     def get_classification_display(self):
     def get_classification_display(self):
-        return dict(PrefixClassificationChoices).get(self.classification)
+        return force_str(dict(PrefixClassificationChoices).get(self.classification), strings_only=True)
 
 
     @cached_property
     @cached_property
     def aggregate(self):
     def aggregate(self):

+ 1 - 0
netbox/ipam/tests/test_tables.py

@@ -216,6 +216,7 @@ class PrefixTableTestCase(TableTestCases.StandardTableTestCase):
         self.assertHTMLEqual(rows[1].get_cell('classification'), '<span class="badge text-bg-green">Private</span>')
         self.assertHTMLEqual(rows[1].get_cell('classification'), '<span class="badge text-bg-green">Private</span>')
         self.assertEqual(rows[0].get_cell_value('classification'), 'Public')
         self.assertEqual(rows[0].get_cell_value('classification'), 'Public')
         self.assertEqual(rows[1].get_cell_value('classification'), 'Private')
         self.assertEqual(rows[1].get_cell_value('classification'), 'Private')
+        self.assertIs(type(rows[0].get_cell_value('classification')), str)
 
 
     def test_classification_ordering(self):
     def test_classification_ordering(self):
         """Available-space rows sort by the classification of their own prefix."""
         """Available-space rows sort by the classification of their own prefix."""