コード例 #1
0
    def moderate(self, comment, content_object, request):
        """
        Determine whether a given comment on a given object should be allowed to show up immediately,
        or should be marked non-public and await approval.

        Returns ``True`` if the comment should be moderated (marked non-public), ``False`` otherwise.
        """

        # Soft delete checks are done first, so these comments are not mistakenly "just moderated"
        # for expiring the `close_after` date, but correctly get marked as spam instead.
        # This helps staff to quickly see which comments need real moderation.
        if self.akismet_check:
            akismet_result = akismet_check(comment, content_object, request)
            if akismet_result:
                # Typically action=delete never gets here, unless the service was having problems.
                if (
                    akismet_result
                    in (
                        SpamStatus.ProbableSpam,
                        SpamStatus.DefiniteSpam,
                    )
                    and self.akismet_check_action in ("auto", "soft_delete", "delete")
                ):
                    comment.is_removed = True  # Set extra marker

                # SpamStatus.Unknown or action=moderate will end up in the moderation queue
                return True

        # Parent class check
        if super().moderate(comment, content_object, request):
            return True

        # Bad words check
        if self.moderate_bad_words:
            input_words = split_words(comment.comment)
            if self.moderate_bad_words.intersection(input_words):
                return True

        # Akismet check
        if self.akismet_check and self.akismet_check_action not in ("soft_delete", "delete"):
            # Return True if akismet marks this comment as spam and we want to moderate it.
            if akismet_check(comment, content_object, request):
                return True

        return False
コード例 #2
0
    def moderate(self, comment, content_object, request):
        """
        Determine whether a given comment on a given object should be allowed to show up immediately,
        or should be marked non-public and await approval.

        Returns ``True`` if the comment should be moderated (marked non-public), ``False`` otherwise.
        """

        # Soft delete checks are done first, so these comments are not mistakenly "just moderated"
        # for expiring the `close_after` date, but correctly get marked as spam instead.
        # This helps staff to quickly see which comments need real moderation.
        if self.akismet_check:
            akismet_result = akismet_check(comment, content_object, request)
            if akismet_result:
                # Typically action=delete never gets here, unless the service was having problems.
                if akismet_result in (SpamStatus.ProbableSpam, SpamStatus.DefiniteSpam) and \
                       self.akismet_check_action in ('auto', 'soft_delete', 'delete'):
                   comment.is_removed = True  # Set extra marker

                # SpamStatus.Unknown or action=moderate will end up in the moderation queue
                return True

        # Parent class check
        if super(FluentCommentsModerator, self).moderate(comment, content_object, request):
            return True

        # Bad words check
        if self.moderate_bad_words:
            input_words = split_words(comment.comment)
            if self.moderate_bad_words.intersection(input_words):
                return True

        # Akismet check
        if self.akismet_check and self.akismet_check_action not in ('soft_delete', 'delete'):
            # Return True if akismet marks this comment as spam and we want to moderate it.
            if akismet_check(comment, content_object, request):
                return True

        return False
コード例 #3
0
    def allow(self, comment, content_object, request):
        """
        Determine whether a given comment is allowed to be posted on a given object.

        Returns ``True`` if the comment should be allowed, ``False`` otherwise.
        """
        # Parent class check
        if not super(FluentCommentsModerator, self).allow(comment, content_object, request):
            return False

        # Akismet check
        if self.akismet_check:
            akismet_result = akismet_check(comment, content_object, request)
            if self.akismet_check_action == 'delete' and akismet_result in (SpamStatus.ProbableSpam, SpamStatus.DefiniteSpam):
                return False  # Akismet marked the comment as spam.
            elif self.akismet_check_action == 'auto' and akismet_result == SpamStatus.DefiniteSpam:
                return False  # Clearly spam

        return True
コード例 #4
0
    def allow(self, comment, content_object, request):
        """
        Determine whether a given comment is allowed to be posted on a given object.

        Returns ``True`` if the comment should be allowed, ``False`` otherwise.
        """
        # Parent class check
        if not super(FluentCommentsModerator, self).allow(
                comment, content_object, request):
            return False

        # Akismet check
        if self.akismet_check:
            akismet_result = akismet_check(comment, content_object, request)
            if self.akismet_check_action == 'delete' and akismet_result in (
                    SpamStatus.ProbableSpam, SpamStatus.DefiniteSpam):
                return False  # Akismet marked the comment as spam.
            elif self.akismet_check_action == 'auto' and akismet_result == SpamStatus.DefiniteSpam:
                return False  # Clearly spam

        return True