diff --git a/model_utils/choices.py b/model_utils/choices.py index 65097c7..b5177cd 100644 --- a/model_utils/choices.py +++ b/model_utils/choices.py @@ -1,3 +1,6 @@ +from __future__ import unicode_literals + + class Choices(object): """ A class to encapsulate handy functionality for lists of choices @@ -72,4 +75,4 @@ class Choices(object): def __repr__(self): return '%s(%s)' % (self.__class__.__name__, - ', '.join(("%s" % str(i) for i in self._full))) + ', '.join(("%s" % repr(i) for i in self._full))) diff --git a/model_utils/fields.py b/model_utils/fields.py index 6dd6459..9178e1f 100644 --- a/model_utils/fields.py +++ b/model_utils/fields.py @@ -1,7 +1,9 @@ +from __future__ import unicode_literals from datetime import datetime from django.db import models from django.conf import settings +from django.utils.encoding import python_2_unicode_compatible try: @@ -128,6 +130,7 @@ def get_excerpt(content): return '\n'.join(default_excerpt) +@python_2_unicode_compatible class SplitText(object): def __init__(self, instance, field_name, excerpt_field_name): # instead of storing actual values store a reference to the instance @@ -153,8 +156,7 @@ class SplitText(object): return self.excerpt.strip() != self.content.strip() has_more = property(_get_has_more) - # allows display via templates without .content necessary - def __unicode__(self): + def __str__(self): return self.content class SplitDescriptor(object): diff --git a/model_utils/managers.py b/model_utils/managers.py index 1f502ad..7c6c9f9 100644 --- a/model_utils/managers.py +++ b/model_utils/managers.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals import django from django.db import models from django.db.models.fields.related import OneToOneField diff --git a/model_utils/models.py b/model_utils/models.py index 40e7aa8..ff8b375 100644 --- a/model_utils/models.py +++ b/model_utils/models.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals from datetime import datetime from django.db import models diff --git a/model_utils/tests/tests.py b/model_utils/tests/tests.py index 02b69ce..2933f21 100644 --- a/model_utils/tests/tests.py +++ b/model_utils/tests/tests.py @@ -1,4 +1,4 @@ -from __future__ import with_statement +from __future__ import unicode_literals, with_statement import pickle from datetime import datetime, timedelta @@ -6,6 +6,7 @@ from datetime import datetime, timedelta import django from django.db import models from django.db.models.fields import FieldDoesNotExist +from django.utils.six import text_type from django.core.exceptions import ImproperlyConfigured, FieldError from django.test import TestCase @@ -47,8 +48,8 @@ class GetExcerptTests(TestCase): class SplitFieldTests(TestCase): - full_text = u'summary\n\n\n\nmore' - excerpt = u'summary\n' + full_text = 'summary\n\n\n\nmore' + excerpt = 'summary\n' def setUp(self): @@ -57,7 +58,7 @@ class SplitFieldTests(TestCase): def test_unicode_content(self): - self.assertEquals(unicode(self.post.body), self.full_text) + self.assertEquals(text_type(self.post.body), self.full_text) def test_excerpt(self): @@ -85,17 +86,17 @@ class SplitFieldTests(TestCase): def test_assign_to_body(self): - new_text = u'different\n\n\n\nother' + new_text = 'different\n\n\n\nother' self.post.body = new_text self.post.save() - self.assertEquals(unicode(self.post.body), new_text) + self.assertEquals(text_type(self.post.body), new_text) def test_assign_to_content(self): - new_text = u'different\n\n\n\nother' + new_text = 'different\n\n\n\nother' self.post.body.content = new_text self.post.save() - self.assertEquals(unicode(self.post.body), new_text) + self.assertEquals(text_type(self.post.body), new_text) def test_assign_to_excerpt(self): @@ -118,7 +119,7 @@ class SplitFieldTests(TestCase): def test_assign_splittext(self): a = Article(title='Some Title') a.body = self.post.body - self.assertEquals(a.body.excerpt, u'summary\n') + self.assertEquals(a.body.excerpt, 'summary\n') def test_value_to_string(self): diff --git a/model_utils/tracker.py b/model_utils/tracker.py index 9a83f1d..a366490 100644 --- a/model_utils/tracker.py +++ b/model_utils/tracker.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals from django.db import models from django.core.exceptions import FieldError