Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12325 -- Allows zero values for moderate_after and close_after…

… 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...
commit 9b7be918edb6a821af786975db645b8f8d261a2c 1 parent 109f42a
Jannis Leidel authored
10  django/contrib/comments/moderation.py
@@ -205,8 +205,9 @@ def allow(self, comment, content_object, request):
205 205
         if self.enable_field:
206 206
             if not getattr(content_object, self.enable_field):
207 207
                 return False
208  
-        if self.auto_close_field and self.close_after:
209  
-            if self._get_delta(datetime.datetime.now(), getattr(content_object, self.auto_close_field)).days >= self.close_after:
  208
+        if self.auto_close_field and self.close_after is not None:
  209
+            close_after_date = getattr(content_object, self.auto_close_field)
  210
+            if close_after_date is not None and self._get_delta(datetime.datetime.now(), close_after_date).days >= self.close_after:
210 211
                 return False
211 212
         return True
212 213
 
@@ -220,8 +221,9 @@ def moderate(self, comment, content_object, request):
220 221
         non-public), ``False`` otherwise.
221 222
 
222 223
         """
223  
-        if self.auto_moderate_field and self.moderate_after:
224  
-            if self._get_delta(datetime.datetime.now(), getattr(content_object, self.auto_moderate_field)).days >= self.moderate_after:
  224
+        if self.auto_moderate_field and self.moderate_after is not None:
  225
+            moderate_after_date = getattr(content_object, self.auto_moderate_field)
  226
+            if moderate_after_date is not None and self._get_delta(datetime.datetime.now(), moderate_after_date).days >= self.moderate_after:
225 227
                 return True
226 228
         return False
227 229
 
12  docs/ref/contrib/comments/moderation.txt
@@ -104,7 +104,9 @@ Built-in moderation options
104 104
         If :attr:`auto_close_field` is used, this must specify the number
105 105
         of days past the value of the field specified by
106 106
         :attr:`auto_close_field` after which new comments for an object
107  
-        should be disallowed. Default value is ``None``.
  107
+        should be disallowed. Allowed values are ``None``, 0 (which disallows
  108
+        comments immediately), or any positive integer. Default value is
  109
+        ``None``.
108 110
 
109 111
     .. attribute:: email_notification
110 112
 
@@ -126,12 +128,18 @@ Built-in moderation options
126 128
         If :attr:`auto_moderate_field` is used, this must specify the number
127 129
         of days past the value of the field specified by
128 130
         :attr:`auto_moderate_field` after which new comments for an object
129  
-        should be marked non-public. Default value is ``None``.
  131
+        should be marked non-public. Allowed values are ``None``, 0 (which
  132
+        moderates comments immediately), or any positive integer. Default
  133
+        value is ``None``.
130 134
 
131 135
 Simply subclassing :class:`CommentModerator` and changing the values of these
132 136
 options will automatically enable the various moderation methods for any
133 137
 models registered using the subclass.
134 138
 
  139
+.. versionchanged:: 1.3
  140
+
  141
+``moderate_after`` and ``close_after`` now accept 0 as a valid value.
  142
+
135 143
 Adding custom moderation methods
136 144
 --------------------------------
137 145
 
18  tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py
@@ -19,6 +19,14 @@ class EntryModerator4(CommentModerator):
19 19
     auto_moderate_field = 'pub_date'
20 20
     moderate_after = 7
21 21
 
  22
+class EntryModerator5(CommentModerator):
  23
+    auto_moderate_field = 'pub_date'
  24
+    moderate_after = 0
  25
+
  26
+class EntryModerator6(CommentModerator):
  27
+    auto_close_field = 'pub_date'
  28
+    close_after = 0
  29
+
22 30
 class CommentUtilsModeratorTests(CommentTestCase):
23 31
     fixtures = ["comment_utils.xml"]
24 32
 
@@ -73,3 +81,13 @@ def testAutoModerateField(self):
73 81
         moderator.register(Entry, EntryModerator4)
74 82
         c1, c2 = self.createSomeComments()
75 83
         self.assertEquals(c2.is_public, False)
  84
+
  85
+    def testAutoModerateFieldImmediate(self):
  86
+        moderator.register(Entry, EntryModerator5)
  87
+        c1, c2 = self.createSomeComments()
  88
+        self.assertEquals(c2.is_public, False)
  89
+
  90
+    def testAutoCloseFieldImmediate(self):
  91
+        moderator.register(Entry, EntryModerator6)
  92
+        c1, c2 = self.createSomeComments()
  93
+        self.assertEquals(Comment.objects.all().count(), 0)

0 notes on commit 9b7be91

Please sign in to comment.
Something went wrong with that request. Please try again.