Permalink
Browse files

Fixed #9282: added a generic comment moderation toolkit. See the docu…

…mentation for details.

This began life as (part of) James Bennett's comment-utils app, and was adapted to be part of Django by Thejaswi Puthraya and Jannis Leidel. Thanks, all!

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10122 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 44f3080 commit f0560dfdb2adaa44fc739941a2a784c558ae6427 @jacobian jacobian committed Mar 23, 2009

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -82,7 +82,7 @@ Other batteries included
* :ref:`Authentication <topics-auth>`
* :ref:`Cache system <topics-cache>`
* :ref:`Conditional content processing <topics-conditional-processing>`
- * :ref:`Comments <ref-contrib-comments-index>`
+ * :ref:`Comments <ref-contrib-comments-index>` | :ref:`Moderation <ref-contrib-comments-moderation>` | :ref:`Custom comments <ref-contrib-comments-custom>`
* :ref:`Content types <ref-contrib-contenttypes>`
* :ref:`Cross Site Request Forgery protection <ref-contrib-csrf>`
* :ref:`Databrowse <ref-contrib-databrowse>`
@@ -216,3 +216,4 @@ More information
upgrade
custom
forms
+ moderation
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<django-objects version="1.0">
+ <object pk="1" model="comment_tests.entry">
+ <field type="CharField" name="title">ABC</field>
+ <field type="TextField" name="body">This is the body</field>
+ <field type="DateField" name="pub_date">2008-01-01</field>
+ <field type="BooleanField" name="enable_comments">True</field>
+ </object>
+ <object pk="2" model="comment_tests.entry">
+ <field type="CharField" name="title">XYZ</field>
+ <field type="TextField" name="body">Text here</field>
+ <field type="DateField" name="pub_date">2008-01-02</field>
+ <field type="BooleanField" name="enable_comments">False</field>
+ </object>
+</django-objects>
@@ -20,3 +20,11 @@ class Article(models.Model):
def __str__(self):
return self.headline
+class Entry(models.Model):
+ title = models.CharField(max_length=250)
+ body = models.TextField()
+ pub_date = models.DateField()
+ enable_comments = models.BooleanField()
+
+ def __str__(self):
+ return self.title
@@ -86,3 +86,4 @@ def getValidData(self, obj):
from regressiontests.comment_tests.tests.templatetag_tests import *
from regressiontests.comment_tests.tests.comment_view_tests import *
from regressiontests.comment_tests.tests.moderation_view_tests import *
+from regressiontests.comment_tests.tests.comment_utils_moderators_tests import *
@@ -0,0 +1,70 @@
+from regressiontests.comment_tests.tests import CommentTestCase, CT, Site
+from django.contrib.comments.models import Comment
+from django.contrib.comments.moderation import moderator, CommentModerator, AlreadyModerated
+from regressiontests.comment_tests.models import Entry
+from django.core import mail
+
+class EntryModerator1(CommentModerator):
+ email_notification = True
+
+class EntryModerator2(CommentModerator):
+ enable_field = 'enable_comments'
+
+class EntryModerator3(CommentModerator):
+ auto_close_field = 'pub_date'
+ close_after = 7
+
+class EntryModerator4(CommentModerator):
+ auto_moderate_field = 'pub_date'
+ moderate_after = 7
+
+class CommentUtilsModeratorTests(CommentTestCase):
+ fixtures = ["comment_utils.xml"]
+
+ def createSomeComments(self):
+ c1 = Comment.objects.create(
+ content_type = CT(Entry),
+ object_pk = "1",
+ user_name = "Joe Somebody",
+ user_email = "jsomebody@example.com",
+ user_url = "http://example.com/~joe/",
+ comment = "First!",
+ site = Site.objects.get_current(),
+ )
+ c2 = Comment.objects.create(
+ content_type = CT(Entry),
+ object_pk = "2",
+ user_name = "Joe the Plumber",
+ user_email = "joetheplumber@whitehouse.gov",
+ user_url = "http://example.com/~joe/",
+ comment = "Second!",
+ site = Site.objects.get_current(),
+ )
+ return c1, c2
+
+ def tearDown(self):
+ moderator.unregister(Entry)
+
+ def testRegisterExistingModel(self):
+ moderator.register(Entry, EntryModerator1)
+ self.assertRaises(AlreadyModerated, moderator.register, Entry, EntryModerator1)
+
+ def testEmailNotification(self):
+ moderator.register(Entry, EntryModerator1)
+ c1, c2 = self.createSomeComments()
+ self.assertEquals(len(mail.outbox), 2)
+
+ def testCommentsEnabled(self):
+ moderator.register(Entry, EntryModerator2)
+ c1, c2 = self.createSomeComments()
+ self.assertEquals(Comment.objects.all().count(), 1)
+
+ def testAutoCloseField(self):
+ moderator.register(Entry, EntryModerator3)
+ c1, c2 = self.createSomeComments()
+ self.assertEquals(Comment.objects.all().count(), 0)
+
+ def testAutoModerateField(self):
+ moderator.register(Entry, EntryModerator4)
+ c1, c2 = self.createSomeComments()
+ self.assertEquals(c2.is_public, False)
View
@@ -110,6 +110,10 @@ def django_tests(verbosity, interactive, test_labels):
'django.middleware.common.CommonMiddleware',
)
settings.SITE_ID = 1
+ # For testing comment-utils, we require the MANAGERS attribute
+ # to be set, so that a test email is sent out which we catch
+ # in our tests.
+ settings.MANAGERS = ("admin@djangoproject.com",)
# Load all the ALWAYS_INSTALLED_APPS.
# (This import statement is intentionally delayed until after we
@@ -0,0 +1,3 @@
+A comment has been posted on {{ content_object }}.
+The comment reads as follows:
+{{ comment }}

0 comments on commit f0560df

Please sign in to comment.