Ticket #12325: 12325_comment_moderation.diff

File 12325_comment_moderation.diff, 4.4 KB (added by Gabriel Hurley, 14 years ago)

New patch with docs and tests

  • django/contrib/comments/moderation.py

     
    205205        if self.enable_field:
    206206            if not getattr(content_object, self.enable_field):
    207207                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:
    210211                return False
    211212        return True
    212213
     
    220221        non-public), ``False`` otherwise.
    221222
    222223        """
    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:
    225227                return True
    226228        return False
    227229
  • docs/ref/contrib/comments/moderation.txt

     
    104104        If :attr:`auto_close_field` is used, this must specify the number
    105105        of days past the value of the field specified by
    106106        :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``.
    108110
    109111    .. attribute:: email_notification
    110112
     
    126128        If :attr:`auto_moderate_field` is used, this must specify the number
    127129        of days past the value of the field specified by
    128130        :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``.
    130134
    131135Simply subclassing :class:`CommentModerator` and changing the values of these
    132136options will automatically enable the various moderation methods for any
    133137models registered using the subclass.
    134138
     139.. versionchanged:: 1.3
     140
     141``moderate_after`` and ``close_after`` now accept 0 as a valid value.
     142
    135143Adding custom moderation methods
    136144--------------------------------
    137145
  • tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py

     
    1919    auto_moderate_field = 'pub_date'
    2020    moderate_after = 7
    2121
     22class EntryModerator5(CommentModerator):
     23    auto_moderate_field = 'pub_date'
     24    moderate_after = 0
     25   
     26class EntryModerator6(CommentModerator):
     27    auto_close_field = 'pub_date'
     28    close_after = 0
     29
    2230class CommentUtilsModeratorTests(CommentTestCase):
    2331    fixtures = ["comment_utils.xml"]
    2432
     
    7381        moderator.register(Entry, EntryModerator4)
    7482        c1, c2 = self.createSomeComments()
    7583        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
Back to Top