Skip to content

Commit 9784990

Browse files
committed
Merge branch 'master' of https://github.com/starshipfactory/django-tagging into feature/fix-unicode-issues
2 parents e82a88d + 0c09642 commit 9784990

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

tagging/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.contrib.contenttypes import generic
55
from django.contrib.contenttypes.models import ContentType
66
from django.db import connection, models
7-
from django.utils.encoding import python_2_unicode_compatible
7+
from django.utils.encoding import python_2_unicode_compatible, smart_text
88
from django.utils.translation import ugettext_lazy as _
99

1010
from . import settings
@@ -490,4 +490,4 @@ class Meta:
490490
verbose_name_plural = _('tagged items')
491491

492492
def __str__(self):
493-
return '%s [%s]' % (self.object, self.tag)
493+
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: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
from django import forms
77
from django.db.models import Q
88
from django.test import TestCase
9+
from django.utils import six
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, Link, Perch, Parrot, FormTest, FormTestNull
15+
from tagging.utils import (calculate_cloud, edit_string_for_tags, get_tag_list,
16+
get_tag, parse_tag_input)
1517
from tagging.utils import LINEAR
1618

1719

@@ -326,6 +328,14 @@ def test_update_tags_exotic_characters(self):
326328
self.assertEqual(len(tags), 1)
327329
self.assertEqual(tags[0].name, '你好')
328330

331+
def test_unicode_tagged_object(self):
332+
self.dead_parrot.state = u"dëad"
333+
self.dead_parrot.save()
334+
Tag.objects.update_tags(self.dead_parrot, u'föo')
335+
items = TaggedItem.objects.all()
336+
self.assertEqual(len(items), 1)
337+
self.assertEqual(six.text_type(items[0]), u"dëad [föo]")
338+
329339
def test_update_tags_with_none(self):
330340
# start off in a known, mildly interesting state
331341
Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')

0 commit comments

Comments
 (0)