Skip to content

Commit

Permalink
Fixed #12325 -- Allows zero values for moderate_after and close_after…
Browse files Browse the repository at this point in the history
… fields of comment moderators. Thanks, Gabriel Hurley.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14556 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jezdez committed Nov 13, 2010
1 parent 109f42a commit 9b7be91
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
10 changes: 6 additions & 4 deletions django/contrib/comments/moderation.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ def allow(self, comment, content_object, request):
if self.enable_field: if self.enable_field:
if not getattr(content_object, self.enable_field): if not getattr(content_object, self.enable_field):
return False return False
if self.auto_close_field and self.close_after: if self.auto_close_field and self.close_after is not None:
if self._get_delta(datetime.datetime.now(), getattr(content_object, self.auto_close_field)).days >= self.close_after: close_after_date = getattr(content_object, self.auto_close_field)
if close_after_date is not None and self._get_delta(datetime.datetime.now(), close_after_date).days >= self.close_after:
return False return False
return True return True


Expand All @@ -220,8 +221,9 @@ def moderate(self, comment, content_object, request):
non-public), ``False`` otherwise. non-public), ``False`` otherwise.
""" """
if self.auto_moderate_field and self.moderate_after: if self.auto_moderate_field and self.moderate_after is not None:
if self._get_delta(datetime.datetime.now(), getattr(content_object, self.auto_moderate_field)).days >= self.moderate_after: moderate_after_date = getattr(content_object, self.auto_moderate_field)
if moderate_after_date is not None and self._get_delta(datetime.datetime.now(), moderate_after_date).days >= self.moderate_after:
return True return True
return False return False


Expand Down
12 changes: 10 additions & 2 deletions docs/ref/contrib/comments/moderation.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ Built-in moderation options
If :attr:`auto_close_field` is used, this must specify the number If :attr:`auto_close_field` is used, this must specify the number
of days past the value of the field specified by of days past the value of the field specified by
:attr:`auto_close_field` after which new comments for an object :attr:`auto_close_field` after which new comments for an object
should be disallowed. Default value is ``None``. should be disallowed. Allowed values are ``None``, 0 (which disallows
comments immediately), or any positive integer. Default value is
``None``.


.. attribute:: email_notification .. attribute:: email_notification


Expand All @@ -126,12 +128,18 @@ Built-in moderation options
If :attr:`auto_moderate_field` is used, this must specify the number If :attr:`auto_moderate_field` is used, this must specify the number
of days past the value of the field specified by of days past the value of the field specified by
:attr:`auto_moderate_field` after which new comments for an object :attr:`auto_moderate_field` after which new comments for an object
should be marked non-public. Default value is ``None``. should be marked non-public. Allowed values are ``None``, 0 (which
moderates comments immediately), or any positive integer. Default
value is ``None``.


Simply subclassing :class:`CommentModerator` and changing the values of these Simply subclassing :class:`CommentModerator` and changing the values of these
options will automatically enable the various moderation methods for any options will automatically enable the various moderation methods for any
models registered using the subclass. models registered using the subclass.


.. versionchanged:: 1.3

``moderate_after`` and ``close_after`` now accept 0 as a valid value.

Adding custom moderation methods Adding custom moderation methods
-------------------------------- --------------------------------


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class EntryModerator4(CommentModerator):
auto_moderate_field = 'pub_date' auto_moderate_field = 'pub_date'
moderate_after = 7 moderate_after = 7


class EntryModerator5(CommentModerator):
auto_moderate_field = 'pub_date'
moderate_after = 0

class EntryModerator6(CommentModerator):
auto_close_field = 'pub_date'
close_after = 0

class CommentUtilsModeratorTests(CommentTestCase): class CommentUtilsModeratorTests(CommentTestCase):
fixtures = ["comment_utils.xml"] fixtures = ["comment_utils.xml"]


Expand Down Expand Up @@ -73,3 +81,13 @@ def testAutoModerateField(self):
moderator.register(Entry, EntryModerator4) moderator.register(Entry, EntryModerator4)
c1, c2 = self.createSomeComments() c1, c2 = self.createSomeComments()
self.assertEquals(c2.is_public, False) self.assertEquals(c2.is_public, False)

def testAutoModerateFieldImmediate(self):
moderator.register(Entry, EntryModerator5)
c1, c2 = self.createSomeComments()
self.assertEquals(c2.is_public, False)

def testAutoCloseFieldImmediate(self):
moderator.register(Entry, EntryModerator6)
c1, c2 = self.createSomeComments()
self.assertEquals(Comment.objects.all().count(), 0)

0 comments on commit 9b7be91

Please sign in to comment.