From c3a867228b34799c9d31f3da3660673fce2d48d0 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Thu, 29 Nov 2007 18:15:31 +0000 Subject: [PATCH] Fixed #5909 -- Made the various django.contrib.comment models more robust in the face of non-ASCII characters by giving them a __unicode__ method and letting the default __repr__ use that. Patches from prairiedogg and scompt. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6742 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/comments/models.py | 10 +++++----- django/contrib/comments/tests.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 django/contrib/comments/tests.py diff --git a/django/contrib/comments/models.py b/django/contrib/comments/models.py index a88d2b3a8e..912f5a6cd2 100644 --- a/django/contrib/comments/models.py +++ b/django/contrib/comments/models.py @@ -102,7 +102,7 @@ class Comment(models.Model): date_hierarchy = 'submit_date' search_fields = ('comment', 'user__username') - def __repr__(self): + def __unicode__(self): return "%s: %s..." % (self.user.username, self.comment[:100]) def get_absolute_url(self): @@ -190,7 +190,7 @@ class FreeComment(models.Model): date_hierarchy = 'submit_date' search_fields = ('comment', 'person_name') - def __repr__(self): + def __unicode__(self): return "%s: %s..." % (self.person_name, self.comment[:100]) def get_absolute_url(self): @@ -244,7 +244,7 @@ class KarmaScore(models.Model): verbose_name_plural = _('karma scores') unique_together = (('user', 'comment'),) - def __repr__(self): + def __unicode__(self): return _("%(score)d rating by %(user)s") % {'score': self.score, 'user': self.user} class UserFlagManager(models.Manager): @@ -275,7 +275,7 @@ class UserFlag(models.Model): verbose_name_plural = _('user flags') unique_together = (('user', 'comment'),) - def __repr__(self): + def __unicode__(self): return _("Flag by %r") % self.user class ModeratorDeletion(models.Model): @@ -287,5 +287,5 @@ class ModeratorDeletion(models.Model): verbose_name_plural = _('moderator deletions') unique_together = (('user', 'comment'),) - def __repr__(self): + def __unicode__(self): return _("Moderator deletion by %r") % self.user diff --git a/django/contrib/comments/tests.py b/django/contrib/comments/tests.py new file mode 100644 index 0000000000..a8275debf6 --- /dev/null +++ b/django/contrib/comments/tests.py @@ -0,0 +1,13 @@ +# coding: utf-8 + +r""" +>>> from django.contrib.comments.models import Comment +>>> from django.contrib.auth.models import User +>>> u = User.objects.create_user('commenttestuser', 'commenttest@example.com', 'testpw') +>>> c = Comment(user=u, comment=u'\xe2') +>>> c + +>>> print c +commenttestuser: â... +""" +