Add __unicode__ representation to Notification and MediaCommentMixin
authorTryggvi Bjorgvinsson <tryggvib@fsfi.is>
Sat, 19 Jul 2014 12:35:50 +0000 (12:35 +0000)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 25 Jul 2014 19:37:57 +0000 (14:37 -0500)
Instead of having __repr__ return a unicode object which it should
not do, we use the __unicode__ method to allow use of Notification
and MediaCommentMixin objects in unicode strings.

mediagoblin/db/mixin.py
mediagoblin/db/models.py

index 3e9ed3a0146133b1c94a0c4385addb2e3b6d531e..1f2e7ec30262d762deab08704059cc15b02bd6f2 100644 (file)
@@ -305,13 +305,20 @@ class MediaCommentMixin(object):
         """
         return cleaned_markdown_conversion(self.content)
 
-    def __repr__(self):
+    def __unicode__(self):
         return u'<{klass} #{id} {author} "{comment}">'.format(
             klass=self.__class__.__name__,
             id=self.id,
             author=self.get_author,
             comment=self.content)
 
+    def __repr__(self):
+        return '<{klass} #{id} {author} "{comment}">'.format(
+            klass=self.__class__.__name__,
+            id=self.id,
+            author=self.get_author,
+            comment=self.content)
+
 
 class CollectionMixin(GenerateSlugMixin):
     def check_slug_used(self, slug):
index aaceb5994d19a951da8fb5fbf4f8144c5c1aafe4..c2d101ac0abb273883f439c3095d65d92e82de8d 100644 (file)
@@ -820,6 +820,14 @@ class Notification(Base):
     }
 
     def __repr__(self):
+        return '<{klass} #{id}: {user}: {subject} ({seen})>'.format(
+            id=self.id,
+            klass=self.__class__.__name__,
+            user=self.user,
+            subject=getattr(self, 'subject', None),
+            seen='unseen' if not self.seen else 'seen')
+
+    def __unicode__(self):
         return u'<{klass} #{id}: {user}: {subject} ({seen})>'.format(
             id=self.id,
             klass=self.__class__.__name__,