From b4e85c7d1c7dcff1deda70f09ff21a6f99d34da7 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 29 Apr 2006 01:08:24 +0000 Subject: [PATCH] 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 --- django/contrib/comments/models.py | 9 +++++---- django/contrib/comments/views/comments.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/django/contrib/comments/models.py b/django/contrib/comments/models.py index 39ac2f678d..f9122b07d5 100644 --- a/django/contrib/comments/models.py +++ b/django/contrib/comments/models.py @@ -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: diff --git a/django/contrib/comments/views/comments.py b/django/contrib/comments/views/comments.py index 5bb869ddba..ecacc1f1c5 100644 --- a/django/contrib/comments/views/comments.py +++ b/django/contrib/comments/views/comments.py @@ -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()}