Author: jezdez
Date: 2010-11-13 12:42:56 -0600 (Sat, 13 Nov 2010)
New Revision: 14556
Modified:
django/trunk/django/contrib/comments/moderation.py
django/trunk/docs/ref/contrib/comments/moderation.txt
django/trunk/tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py
Log:
Fixed #12325 -- Allows zero values for moderate_after and close_after fields of
comment moderators. Thanks, Gabriel Hurley.
Modified: django/trunk/django/contrib/comments/moderation.py
===================================================================
--- django/trunk/django/contrib/comments/moderation.py 2010-11-13 18:42:31 UTC
(rev 14555)
+++ django/trunk/django/contrib/comments/moderation.py 2010-11-13 18:42:56 UTC
(rev 14556)
@@ -205,8 +205,9 @@
if self.enable_field:
if not getattr(content_object, self.enable_field):
return False
- if self.auto_close_field and self.close_after:
- if self._get_delta(datetime.datetime.now(),
getattr(content_object, self.auto_close_field)).days >= self.close_after:
+ if self.auto_close_field and self.close_after is not None:
+ 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 True
@@ -220,8 +221,9 @@
non-public), ``False`` otherwise.
"""
- if self.auto_moderate_field and self.moderate_after:
- if self._get_delta(datetime.datetime.now(),
getattr(content_object, self.auto_moderate_field)).days >= self.moderate_after:
+ if self.auto_moderate_field and self.moderate_after is not None:
+ 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 False
Modified: django/trunk/docs/ref/contrib/comments/moderation.txt
===================================================================
--- django/trunk/docs/ref/contrib/comments/moderation.txt 2010-11-13
18:42:31 UTC (rev 14555)
+++ django/trunk/docs/ref/contrib/comments/moderation.txt 2010-11-13
18:42:56 UTC (rev 14556)
@@ -104,7 +104,9 @@
If :attr:`auto_close_field` is used, this must specify the number
of days past the value of the field specified by
: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
@@ -126,12 +128,18 @@
If :attr:`auto_moderate_field` is used, this must specify the number
of days past the value of the field specified by
: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
options will automatically enable the various moderation methods for any
models registered using the subclass.
+.. versionchanged:: 1.3
+
+``moderate_after`` and ``close_after`` now accept 0 as a valid value.
+
Adding custom moderation methods
--------------------------------
Modified:
django/trunk/tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py
===================================================================
---
django/trunk/tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py
2010-11-13 18:42:31 UTC (rev 14555)
+++
django/trunk/tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py
2010-11-13 18:42:56 UTC (rev 14556)
@@ -19,6 +19,14 @@
auto_moderate_field = 'pub_date'
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):
fixtures = ["comment_utils.xml"]
@@ -73,3 +81,13 @@
moderator.register(Entry, EntryModerator4)
c1, c2 = self.createSomeComments()
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)
\ No newline at end of file
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.