Fixed #4189 -- Fixed crashes in a couple of corner cases in the comments app. Not a perfect fix (see ticket), but it will do as a holdover until the new comments framework is in place.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5848 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-08-11 10:50:39 +00:00
parent 9309a8d6c3
commit 9d7dc0c4bf
4 changed files with 12 additions and 5 deletions

View File

@ -131,6 +131,7 @@ answer newbie questions, and generally made Django that much better:
Joe Heck <http://www.rhonabwy.com/wp/> Joe Heck <http://www.rhonabwy.com/wp/>
Joel Heenan <joelh-django@planetjoel.com> Joel Heenan <joelh-django@planetjoel.com>
hipertracker@gmail.com hipertracker@gmail.com
Brett Hoerner <bretthoerner@bretthoerner.com>
Ian Holsman <http://feh.holsman.net/> Ian Holsman <http://feh.holsman.net/>
Kieran Holland <http://www.kieranholland.com> Kieran Holland <http://www.kieranholland.com>
Sung-Jin Hong <serialx.net@gmail.com> Sung-Jin Hong <serialx.net@gmail.com>

View File

@ -106,7 +106,10 @@ class Comment(models.Model):
return "%s: %s..." % (self.user.username, self.comment[:100]) return "%s: %s..." % (self.user.username, self.comment[:100])
def get_absolute_url(self): def get_absolute_url(self):
return self.get_content_object().get_absolute_url() + "#c" + str(self.id) try:
return self.get_content_object().get_absolute_url() + "#c" + str(self.id)
except AttributeError:
return ""
def get_crossdomain_url(self): def get_crossdomain_url(self):
return "/r/%d/%d/" % (self.content_type_id, self.object_id) return "/r/%d/%d/" % (self.content_type_id, self.object_id)
@ -191,7 +194,10 @@ class FreeComment(models.Model):
return "%s: %s..." % (self.person_name, self.comment[:100]) return "%s: %s..." % (self.person_name, self.comment[:100])
def get_absolute_url(self): def get_absolute_url(self):
return self.get_content_object().get_absolute_url() + "#c" + str(self.id) try:
return self.get_content_object().get_absolute_url() + "#c" + str(self.id)
except AttributeError:
return ""
def get_content_object(self): def get_content_object(self):
""" """

View File

@ -112,9 +112,9 @@ class CommentListNode(template.Node):
'site__id__exact': settings.SITE_ID, 'site__id__exact': settings.SITE_ID,
} }
kwargs.update(self.extra_kwargs) kwargs.update(self.extra_kwargs)
if not self.free and settings.COMMENTS_BANNED_USERS_GROUP:
kwargs['select'] = {'is_hidden': 'user_id IN (SELECT user_id FROM auth_user_groups WHERE group_id = %s)' % settings.COMMENTS_BANNED_USERS_GROUP}
comment_list = get_list_function(**kwargs).order_by(self.ordering + 'submit_date').select_related() comment_list = get_list_function(**kwargs).order_by(self.ordering + 'submit_date').select_related()
if not self.free and settings.COMMENTS_BANNED_USERS_GROUP:
comment_list = comment_list.extra(select={'is_hidden': 'user_id IN (SELECT user_id FROM auth_user_groups WHERE group_id = %s)' % settings.COMMENTS_BANNED_USERS_GROUP})
if not self.free: if not self.free:
if 'user' in context and context['user'].is_authenticated(): if 'user' in context and context['user'].is_authenticated():

View File

@ -113,7 +113,7 @@ class PublicCommentManipulator(AuthenticationForm):
'This comment was posted by a user who has posted fewer than %(count)s comments:\n\n%(text)s', settings.COMMENTS_FIRST_FEW) % \ 'This comment was posted by a user who has posted fewer than %(count)s comments:\n\n%(text)s', settings.COMMENTS_FIRST_FEW) % \
{'count': settings.COMMENTS_FIRST_FEW, 'text': c.get_as_text()} {'count': settings.COMMENTS_FIRST_FEW, 'text': c.get_as_text()}
mail_managers("Comment posted by rookie user", message) mail_managers("Comment posted by rookie user", message)
if settings.COMMENTS_SKETCHY_USERS_GROUP and settings.COMMENTS_SKETCHY_USERS_GROUP in [g.id for g in self.user_cache.get_group_list()]: if settings.COMMENTS_SKETCHY_USERS_GROUP and settings.COMMENTS_SKETCHY_USERS_GROUP in [g.id for g in self.user_cache.groups.all()]:
message = _('This comment was posted by a sketchy user:\n\n%(text)s') % {'text': c.get_as_text()} message = _('This comment was posted by a sketchy user:\n\n%(text)s') % {'text': c.get_as_text()}
mail_managers("Comment posted by sketchy user (%s)" % self.user_cache.username, c.get_as_text()) mail_managers("Comment posted by sketchy user (%s)" % self.user_cache.username, c.get_as_text())
return c return c