diff --git a/django/contrib/comments/managers.py b/django/contrib/comments/managers.py
index 499feee..45c81c3 100644
a
|
b
|
|
1 | 1 | from django.db import models |
| 2 | from django.conf import settings |
2 | 3 | from django.contrib.contenttypes.models import ContentType |
3 | 4 | from django.utils.encoding import force_unicode |
4 | 5 | |
5 | | class CommentManager(models.Manager): |
6 | | |
| 6 | class CommentQuerySet(models.query.QuerySet): |
7 | 7 | def in_moderation(self): |
8 | 8 | """ |
9 | 9 | QuerySet for all comments currently in the moderation queue. |
10 | 10 | """ |
11 | | return self.get_query_set().filter(is_public=False, is_removed=False) |
| 11 | return self.filter(is_public=False, is_removed=False) |
| 12 | |
| 13 | def not_in_moderation(self): |
| 14 | """ |
| 15 | QuerySet for all comments currently not in the moderation queue, i.e., |
| 16 | all the comments that are publicly viewable. |
| 17 | """ |
| 18 | # The is_public and is_removed fields are implementation details of the |
| 19 | # built-in comment model's spam filtering system, so they might not |
| 20 | # be present on a custom comment model subclass. If they exist, we |
| 21 | # should filter on them. |
| 22 | field_names = [f.name for f in self.model._meta.fields] |
| 23 | if 'is_public' in field_names: |
| 24 | qs = self.filter(is_public=True) |
| 25 | if getattr(settings, 'COMMENTS_HIDE_REMOVED', True) and 'is_removed' in field_names: |
| 26 | qs = qs.filter(is_removed=False) |
| 27 | return qs |
12 | 28 | |
13 | 29 | def for_model(self, model): |
14 | 30 | """ |
… |
… |
class CommentManager(models.Manager):
|
16 | 32 | a class). |
17 | 33 | """ |
18 | 34 | ct = ContentType.objects.get_for_model(model) |
19 | | qs = self.get_query_set().filter(content_type=ct) |
| 35 | qs = self.filter(content_type=ct) |
20 | 36 | if isinstance(model, models.Model): |
21 | 37 | qs = qs.filter(object_pk=force_unicode(model._get_pk_val())) |
22 | 38 | return qs |
| 39 | |
| 40 | class CommentManager(models.Manager): |
| 41 | |
| 42 | def get_query_set(self): |
| 43 | return CommentQuerySet(self.model, using=self._db) |
| 44 | |
| 45 | def in_moderation(self): |
| 46 | """ |
| 47 | QuerySet for all comments currently in the moderation queue. |
| 48 | """ |
| 49 | return self.get_query_set().in_moderation() |
| 50 | |
| 51 | def not_in_moderation(self): |
| 52 | """ |
| 53 | QuerySet for all comments currently not in the moderation queue, i.e., |
| 54 | all the comments that are publicly viewable. |
| 55 | """ |
| 56 | return self.get_query_set().not_in_moderation() |
| 57 | |
| 58 | def for_model(self, model): |
| 59 | """ |
| 60 | QuerySet for all comments for a particular model (either an instance or |
| 61 | a class). |
| 62 | """ |
| 63 | return self.get_query_set().for_model(model) |
diff --git a/django/contrib/comments/templatetags/comments.py b/django/contrib/comments/templatetags/comments.py
index ce1825e..0aded1c 100644
a
|
b
|
class BaseCommentNode(template.Node):
|
79 | 79 | site__pk = settings.SITE_ID, |
80 | 80 | ) |
81 | 81 | |
82 | | # The is_public and is_removed fields are implementation details of the |
83 | | # built-in comment model's spam filtering system, so they might not |
84 | | # be present on a custom comment model subclass. If they exist, we |
85 | | # should filter on them. |
86 | | field_names = [f.name for f in self.comment_model._meta.fields] |
87 | | if 'is_public' in field_names: |
88 | | qs = qs.filter(is_public=True) |
89 | | if getattr(settings, 'COMMENTS_HIDE_REMOVED', True) and 'is_removed' in field_names: |
90 | | qs = qs.filter(is_removed=False) |
91 | | |
92 | | return qs |
| 82 | return qs.not_in_moderation() |
93 | 83 | |
94 | 84 | def get_target_ctype_pk(self, context): |
95 | 85 | if self.object_expr: |
diff --git a/tests/regressiontests/comment_tests/tests/model_tests.py b/tests/regressiontests/comment_tests/tests/model_tests.py
index 2cbf66f..36be29b 100644
a
|
b
|
class CommentManagerTests(CommentTestCase):
|
30 | 30 | moderated_comments = list(Comment.objects.in_moderation().order_by("id")) |
31 | 31 | self.assertEqual(moderated_comments, [c1, c2]) |
32 | 32 | |
| 33 | def testGetCommentsForModel(self): |
| 34 | c1, c2, c3, c4 = self.createSomeComments() |
| 35 | comments_for_model = list(Comment.objects.for_model(Article).order_by("id")) |
| 36 | self.assertEqual(comments_for_model, [c1, c3]) |
| 37 | |
33 | 38 | def testRemovedCommentsNotInModeration(self): |
34 | 39 | """Removed comments are not considered in moderation""" |
35 | 40 | c1, c2, c3, c4 = self.createSomeComments() |