1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

magic-removal: Fixed #1709 -- Updated comments app to use magic-removal APIs. Thanks, Eric Hsu

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2775 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-04-29 01:08:24 +00:00
parent f4eb6b118a
commit b4e85c7d1c
2 changed files with 6 additions and 5 deletions

View File

@ -47,10 +47,11 @@ class CommentManager(models.Manager):
Returns a list of Comment objects matching the given lookup terms, with
_karma_total_good and _karma_total_bad filled.
"""
kwargs.setdefault('select', {})
kwargs['select']['_karma_total_good'] = 'SELECT COUNT(*) FROM comments_karmascore WHERE comments_karmascore.comment_id=comments.id AND score=1'
kwargs['select']['_karma_total_bad'] = 'SELECT COUNT(*) FROM comments_karmascore WHERE comments_karmascore.comment_id=comments.id AND score=-1'
return self.filter(**kwargs)
extra_kwargs = {}
extra_kwargs.setdefault('select', {})
extra_kwargs['select']['_karma_total_good'] = 'SELECT COUNT(*) FROM comments_karmascore, comments_comment WHERE comments_karmascore.comment_id=comments_comment.id AND score=1'
extra_kwargs['select']['_karma_total_bad'] = 'SELECT COUNT(*) FROM comments_karmascore, comments_comment WHERE comments_karmascore.comment_id=comments_comment.id AND score=-1'
return self.filter(**kwargs).extra(**extra_kwargs)
def user_is_moderator(self, user):
if user.is_superuser:

View File

@ -108,7 +108,7 @@ class PublicCommentManipulator(AuthenticationForm):
c.save()
# If the commentor has posted fewer than COMMENTS_FIRST_FEW comments,
# send the comment to the managers.
if self.user_cache.get_comments_comment_count() <= settings.COMMENTS_FIRST_FEW:
if self.user_cache.comment_set.count() <= settings.COMMENTS_FIRST_FEW:
message = ngettext('This comment was posted by a user who has posted fewer than %(count)s comment:\n\n%(text)s',
'This comment was posted by a user who has posted fewer than %(count)s comments:\n\n%(text)s') % \
{'count': settings.COMMENTS_FIRST_FEW, 'text': c.get_as_text()}