Kaydet (Commit) f0560dfd authored tarafından Jacob Kaplan-Moss's avatar Jacob Kaplan-Moss

Fixed #9282: added a generic comment moderation toolkit. See the documentation 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
üst 44f30802
This diff is collapsed.
......@@ -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
\ No newline at end of file
<?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 @@ from regressiontests.comment_tests.tests.comment_form_tests import *
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 *
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)
......@@ -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
......
A comment has been posted on {{ content_object }}.
The comment reads as follows:
{{ comment }}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment