Пример #1
0
 def mark_ham(self, modeladmin, request, queryset):
     for comment in queryset:
         utils.classify_comment(comment, cls='ham')
     self.message_user(
         request,
         "%s comment(s) successfully marked as ham." % queryset.count()
     )
Пример #2
0
def report_comment(request, content_type, id, vote):
    comment = Comment.objects.get(id=id)

    classify_comment(comment, 'reported')
    user = comment.user

    if user is not None:
        ban_user(user, 1, get_user(request))

    return redirect(request.GET.get('next', reverse('home')))
Пример #3
0
def realtime_comment_classifier(sender, instance, created, **kwargs):
    """
    Classifies a comment after it has been created.

    This behaviour is configurable by the REALTIME_CLASSIFICATION MODERATOR,
    default behaviour is to classify(True).
    """
    # Only classify if newly created.
    if created:
        moderator_settings = getattr(settings, 'MODERATOR', None)
        if moderator_settings:
            if 'REALTIME_CLASSIFICATION' in moderator_settings:
                if not moderator_settings['REALTIME_CLASSIFICATION']:
                    return

        # Only classify if not a reply comment.
        if not getattr(instance, 'is_reply_comment', False):
            from moderator.utils import classify_comment
            classify_comment(instance)
Пример #4
0
    def handle(self, *args, **options):
        # Collect all comments that hasn't already been classified or are classified as unsure.
        # Order randomly so we don't rehash previously unsure classifieds when count limiting.
        comments = Comment.objects.filter(Q(classifiedcomment__isnull=True) | Q(classifiedcomment__cls='unsure')).order_by('?')
        if options['count']:
            comments = comments[:options['count']]
        comment_count = comments.count()

        self.stdout.write('Classifying %s comments, please wait...' % comment_count)
        self.stdout.flush()

        for comment in comments:
            classified_comment = utils.classify_comment(comment)
            self.stdout.write('%s,' % classified_comment.cls[0])
            self.stdout.flush()

        self.stdout.write('\nDone!\n')