mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #3721: Allow Unicode characters in tag slugs
This commit is contained in:
@@ -10,6 +10,7 @@ from django.db import models
|
||||
from django.http import HttpResponse
|
||||
from django.template import Template, Context
|
||||
from django.urls import reverse
|
||||
from django.utils.text import slugify
|
||||
from taggit.models import TagBase, GenericTaggedItemBase
|
||||
|
||||
from utilities.fields import ColorField
|
||||
@@ -952,6 +953,13 @@ class Tag(TagBase, ChangeLoggedModel):
|
||||
def get_absolute_url(self):
|
||||
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):
|
||||
tag = models.ForeignKey(
|
||||
|
@@ -3,7 +3,7 @@ from django.test import TestCase
|
||||
|
||||
from dcim.models import Site
|
||||
from extras.choices import TemplateLanguageChoices
|
||||
from extras.models import Graph
|
||||
from extras.models import Graph, Tag
|
||||
|
||||
|
||||
class GraphTest(TestCase):
|
||||
@@ -44,3 +44,12 @@ class GraphTest(TestCase):
|
||||
|
||||
self.assertEqual(graph.embed_url(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-台灣')
|
||||
|
Reference in New Issue
Block a user