diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-11-29 18:15:31 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-11-29 18:15:31 +0000 |
| commit | c3a867228b34799c9d31f3da3660673fce2d48d0 (patch) | |
| tree | 626bbcf5db1a61797b6cf6f3201f6e6dd71c13c7 | |
| parent | f86e54e3b0520fa954e1cabbf67752ef9b99c78f (diff) | |
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
| -rw-r--r-- | django/contrib/comments/models.py | 10 | ||||
| -rw-r--r-- | django/contrib/comments/tests.py | 13 |
2 files changed, 18 insertions, 5 deletions
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 +<Comment: commenttestuser: â...> +>>> print c +commenttestuser: â... +""" + |
