mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Fixes #3721: Allow Unicode characters in tag slugs
This commit is contained in:
parent
aa73a7ad02
commit
606f3dacbb
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
|
|
||||||
|
* [#3721](https://github.com/netbox-community/netbox/issues/3721) - Allow Unicode characters in tag slugs
|
||||||
* [#3951](https://github.com/netbox-community/netbox/issues/3951) - Fix exception in webhook worker due to missing constant
|
* [#3951](https://github.com/netbox-community/netbox/issues/3951) - Fix exception in webhook worker due to missing constant
|
||||||
* [#3953](https://github.com/netbox-community/netbox/issues/3953) - Fix validation error when creating child devices
|
* [#3953](https://github.com/netbox-community/netbox/issues/3953) - Fix validation error when creating child devices
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ from django.db import models
|
|||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.template import Template, Context
|
from django.template import Template, Context
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from django.utils.text import slugify
|
||||||
from taggit.models import TagBase, GenericTaggedItemBase
|
from taggit.models import TagBase, GenericTaggedItemBase
|
||||||
|
|
||||||
from utilities.fields import ColorField
|
from utilities.fields import ColorField
|
||||||
@ -952,6 +953,13 @@ class Tag(TagBase, ChangeLoggedModel):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('extras:tag', args=[self.slug])
|
return reverse('extras:tag', args=[self.slug])
|
||||||
|
|
||||||
|
def slugify(self, tag, i=None):
|
||||||
|
# Allow Unicode in Tag slugs (avoids empty slugs for Tags with all-Unicode names)
|
||||||
|
slug = slugify(tag, allow_unicode=True)
|
||||||
|
if i is not None:
|
||||||
|
slug += "_%d" % i
|
||||||
|
return slug
|
||||||
|
|
||||||
|
|
||||||
class TaggedItem(GenericTaggedItemBase):
|
class TaggedItem(GenericTaggedItemBase):
|
||||||
tag = models.ForeignKey(
|
tag = models.ForeignKey(
|
||||||
|
@ -3,7 +3,7 @@ from django.test import TestCase
|
|||||||
|
|
||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from extras.choices import TemplateLanguageChoices
|
from extras.choices import TemplateLanguageChoices
|
||||||
from extras.models import Graph
|
from extras.models import Graph, Tag
|
||||||
|
|
||||||
|
|
||||||
class GraphTest(TestCase):
|
class GraphTest(TestCase):
|
||||||
@ -44,3 +44,12 @@ class GraphTest(TestCase):
|
|||||||
|
|
||||||
self.assertEqual(graph.embed_url(self.site), RENDERED_TEXT)
|
self.assertEqual(graph.embed_url(self.site), RENDERED_TEXT)
|
||||||
self.assertEqual(graph.embed_link(self.site), RENDERED_TEXT)
|
self.assertEqual(graph.embed_link(self.site), RENDERED_TEXT)
|
||||||
|
|
||||||
|
|
||||||
|
class TagTest(TestCase):
|
||||||
|
|
||||||
|
def test_create_tag_unicode(self):
|
||||||
|
tag = Tag(name='Testing Unicode: 台灣')
|
||||||
|
tag.save()
|
||||||
|
|
||||||
|
self.assertEqual(tag.slug, 'testing-unicode-台灣')
|
||||||
|
Loading…
Reference in New Issue
Block a user