guys,
today while I'm using the comments module to implement something, I
guess I found two bugs:
1. in the models.py, the get_list_with_karma method should be updated
to use the extra() method to inject the "select" kwargs, otherwise, the
templatetag get_comment_list won't work;
2. in the views/comments.py,
self.user_cache.get_comments_comment_count() - the
get_comments_comment_count() api doesn't exist now, should be updated
to use the self.user_cache.comment_set.count() to get the comments
count.
here is the patch:
Index: models.py
===
--- models.py (revision 2750)
+++ models.py (working copy)
@@ -47,10 +47,16 @@
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'
+ # uncomment the following 4 lines for debugging
+ #res = self.filter(**kwargs).extra(**extra_kwargs)
+ #from django.db import connection
+ #sql = connection.queries
+ #raise IOError
+return self.filter(**kwargs).extra(**extra_kwargs)
def user_is_moderator(self, user):
if user.is_superuser:
Index: views/comments.py
===
--- views/comments.py (revision 2750)
+++ views/comments.py (working copy)
@@ -108,7 +108,7 @@
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()}
I've done some debug work to check the patch for models.py, pls check
the the following sqls to confirm if my patch work as expected:
before patching:
{'sql': 'SELECT
"comments_comment"."id","comments_comment"."user_id","comments_comment"."content_type_id","comments_comment"."object_id","comments_comment"."headline","comments_comment"."comment","comments_comment"."rating1","comments_comment"."rating2","comments_comment"."rating3","comments_comment"."rating4","comments_comment"."rating5","comments_comment"."rating6","comments_comment"."rating7","comments_comment"."rating8","comments_comment"."valid_rating","comments_comment"."submit_date","comments_comment"."is_public","comments_comment"."ip_address","comments_comment"."is_removed","comments_comment"."site_id"
FROM "comments_comment" INNER JOIN "django_content_type" AS
"comments_comment__content_type" ON
"comments_comment"."content_type_id" =
"comments_comment__content_type"."id" WHERE
("comments_comment__content_type"."model" = article AND
"comments_comment"."site_id" = 1 AND
"comments_comment__content_type"."app_label" = aiyo AND
"comments_comment"."object_id" = 32) ORDER BY
"comments_comment"."submit_date" DESC',
'time': '0.001'},
---
patched:
{'sql': 'SELECT
"comments_comment"."id","comments_comment"."user_id","comments_comment"."content_type_id","comments_comment"."object_id","comments_comment"."headline","comments_comment"."comment","comments_comment"."rating1","comments_comment"."rating2","comments_comment"."rating3","comments_comment"."rating4","comments_comment"."rating5","comments_comment"."rating6","comments_comment"."rating7","comments_comment"."rating8","comments_comment"."valid_rating","comments_comment"."submit_date","comments_comment"."is_public","comments_comment"."ip_address","comments_comment"."is_removed","comments_comment"."site_id",(SELECT
COUNT(*) FROM comments_karmascore, comments_comment WHERE
comments_karmascore.comment_id=comments_comment.id AND score=1) AS
"_karma_total_good",(SELECT COUNT(*) FROM comments_karmascore,
comments_comment WHERE
comments_karmascore.comment_id=comments_comment.id AN