Ticket #12325: 12325_comment_moderation.diff
File 12325_comment_moderation.diff, 4.4 KB (added by , 14 years ago) |
---|
-
django/contrib/comments/moderation.py
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 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 -
docs/ref/contrib/comments/moderation.txt
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 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 -
tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py
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 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) 94 No newline at end of file