Browse Source

#609: renamed __unicode__ to __str__, added decorators for backwards compat

Rafał Pitoń 8 years ago
parent
commit
df645c98d5

+ 3 - 1
misago/acl/models.py

@@ -1,6 +1,7 @@
 # pylint: disable=attribute-defined-outside-init,pointless-string-statement
 from django.db import models
 from django.dispatch import receiver
+from django.utils.encoding import python_2_unicode_compatible
 
 from misago.core import serializer
 from misago.core.signals import secret_key_changed
@@ -8,6 +9,7 @@ from misago.core.signals import secret_key_changed
 from . import version as acl_version
 
 
+@python_2_unicode_compatible
 class BaseRole(models.Model):
     name = models.CharField(max_length=255)
     special_role = models.CharField(max_length=255, null=True, blank=True)
@@ -16,7 +18,7 @@ class BaseRole(models.Model):
     class Meta:
         abstract = True
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     def save(self, *args, **kwargs):

+ 5 - 1
misago/threads/models/post.py

@@ -1,9 +1,12 @@
+from __future import unicode_literals
+
 import copy
 
 from django.contrib.postgres.fields import JSONField
 from django.core.urlresolvers import reverse
 from django.db import models
 from django.dispatch import receiver
+from django.utils.encoding import python_2_unicode_compatible
 from django.utils import six, timezone
 
 from misago.conf import settings
@@ -14,6 +17,7 @@ from .. import threadtypes
 from ..checksums import is_post_valid, update_post_checksum
 
 
+@python_2_unicode_compatible
 class Post(models.Model):
     category = models.ForeignKey('misago_categories.Category')
     thread = models.ForeignKey('misago_threads.Thread')
@@ -83,7 +87,7 @@ class Post(models.Model):
             ('poster', 'posted_on')
         ]
 
-    def __unicode__(self):
+    def __str__(self):
         return '%s...' % self.original[10:].strip()
 
     def delete(self, *args, **kwargs):

+ 3 - 1
misago/threads/models/thread.py

@@ -1,4 +1,5 @@
 from django.db import models, transaction
+from django.utils.encoding import python_2_unicode_compatible
 from django.utils.translation import ugettext_lazy as _
 
 from misago.conf import settings
@@ -26,6 +27,7 @@ THREAD_WEIGHT_CHOICES = (
 )
 
 
+@python_2_unicode_compatible
 class Thread(models.Model):
     category = models.ForeignKey('misago_categories.Category')
     title = models.CharField(max_length=255)
@@ -94,7 +96,7 @@ class Thread(models.Model):
             ['category', 'replies'],
         ]
 
-    def __unicode__(self):
+    def __str__(self):
         return self.title
 
     def lock(self):

+ 5 - 1
misago/threads/moderation/exceptions.py

@@ -1,6 +1,10 @@
+from django.utils.encoding import python_2_unicode_compatible
+
+
+@python_2_unicode_compatible
 class ModerationError(Exception):
     def __init__(self, message):
         self.message = message
 
-    def __unicode__(self):
+    def __str__(self):
         return self.message

+ 4 - 4
misago/users/models/rank.py

@@ -1,13 +1,12 @@
 from django.core.urlresolvers import reverse
 from django.db import models, transaction
+from django.utils.encoding import python_2_unicode_compatible
 
 from misago.acl import version as acl_version
 from misago.core.utils import slugify
 
 
-__all__ = [
-    'Rank'
-]
+__all__ = ['Rank']
 
 
 class RankManager(models.Manager):
@@ -21,6 +20,7 @@ class RankManager(models.Manager):
             rank.save(update_fields=['is_default'])
 
 
+@python_2_unicode_compatible
 class Rank(models.Model):
     name = models.CharField(max_length=255)
     slug = models.CharField(unique=True, max_length=255)
@@ -37,7 +37,7 @@ class Rank(models.Model):
     class Meta:
         get_latest_by = 'order'
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     def save(self, *args, **kwargs):

+ 3 - 1
misago/users/models/warnings.py

@@ -4,6 +4,7 @@ from datetime import timedelta
 from django.conf import settings
 from django.db import models
 from django.utils import timezone
+from django.utils.encoding import python_2_unicode_compatible
 from django.utils.translation import ugettext_lazy as _
 
 from misago.core import threadstore
@@ -55,6 +56,7 @@ class WarningLevelManager(models.Manager):
         return OrderedDict(levels)
 
 
+@python_2_unicode_compatible
 class WarningLevel(models.Model):
     name = models.CharField(max_length=255)
     level = models.PositiveIntegerField(default=1, db_index=True)
@@ -66,7 +68,7 @@ class WarningLevel(models.Model):
 
     objects = WarningLevelManager()
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     def save(self, *args, **kwargs):