0
0
mirror of https://github.com/django/django.git synced 2024-11-30 07:06:18 +01:00

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
This commit is contained in:
Malcolm Tredinnick 2007-11-29 18:15:31 +00:00
parent f86e54e3b0
commit c3a867228b
2 changed files with 18 additions and 5 deletions

View File

@ -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

View File

@ -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: â...
"""