Skip to content

Commit 651cdc3

Browse files
committed
Merge branch 'feature/fix-unicode-issues' into develop
2 parents e82a88d + 78988e4 commit 651cdc3

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

tagging/models.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
"""
22
Models and managers for generic tagging.
33
"""
4+
from django.db import models
5+
from django.db import connection
6+
from django.utils.encoding import smart_text
7+
from django.utils.encoding import python_2_unicode_compatible
48
from django.contrib.contenttypes import generic
59
from django.contrib.contenttypes.models import ContentType
6-
from django.db import connection, models
7-
from django.utils.encoding import python_2_unicode_compatible
810
from django.utils.translation import ugettext_lazy as _
911

1012
from . import settings
11-
from .utils import (calculate_cloud, get_tag_list, get_queryset_and_model,
12-
parse_tag_input, LOGARITHMIC)
13+
from .utils import LOGARITHMIC
14+
from .utils import get_tag_list
15+
from .utils import calculate_cloud
16+
from .utils import parse_tag_input
17+
from .utils import get_queryset_and_model
1318

1419

1520
qn = connection.ops.quote_name
@@ -490,4 +495,4 @@ class Meta:
490495
verbose_name_plural = _('tagged items')
491496

492497
def __str__(self):
493-
return '%s [%s]' % (self.object, self.tag)
498+
return '%s [%s]' % (smart_text(self.object), smart_text(self.tag))

tagging/tests/models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from tagging.fields import TagField
55

66

7-
@python_2_unicode_compatible
87
class Perch(models.Model):
98
size = models.IntegerField()
109
smelly = models.BooleanField(default=True)
@@ -44,11 +43,9 @@ class Meta:
4443
ordering = ['name']
4544

4645

47-
@python_2_unicode_compatible
4846
class FormTest(models.Model):
4947
tags = TagField('Test', help_text='Test')
5048

5149

52-
@python_2_unicode_compatible
5350
class FormTestNull(models.Model):
5451
tags = TagField(null=True)

tagging/tests/tests.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@
44
import os
55

66
from django import forms
7+
from django.utils import six
78
from django.db.models import Q
89
from django.test import TestCase
910

1011
from tagging import settings
1112
from tagging.forms import TagField
1213
from tagging.models import Tag, TaggedItem
13-
from tagging.tests.models import Article, Link, Perch, Parrot, FormTest
14-
from tagging.utils import calculate_cloud, edit_string_for_tags, get_tag_list, get_tag, parse_tag_input
14+
from tagging.tests.models import Article
15+
from tagging.tests.models import Link
16+
from tagging.tests.models import Perch
17+
from tagging.tests.models import Parrot
18+
from tagging.tests.models import FormTest
19+
from tagging.tests.models import FormTestNull
1520
from tagging.utils import LINEAR
16-
21+
from tagging.utils import get_tag
22+
from tagging.utils import get_tag_list
23+
from tagging.utils import calculate_cloud
24+
from tagging.utils import parse_tag_input
25+
from tagging.utils import edit_string_for_tags
1726

1827
#############
1928
# Utilities #
@@ -326,6 +335,14 @@ def test_update_tags_exotic_characters(self):
326335
self.assertEqual(len(tags), 1)
327336
self.assertEqual(tags[0].name, '你好')
328337

338+
def test_unicode_tagged_object(self):
339+
self.dead_parrot.state = u"dëad"
340+
self.dead_parrot.save()
341+
Tag.objects.update_tags(self.dead_parrot, u'föo')
342+
items = TaggedItem.objects.all()
343+
self.assertEqual(len(items), 1)
344+
self.assertEqual(six.text_type(items[0]), u"dëad [föo]")
345+
329346
def test_update_tags_with_none(self):
330347
# start off in a known, mildly interesting state
331348
Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')

0 commit comments

Comments
 (0)