<commit_before>from django import template
from django.conf import settings
from likes.utils import can_vote
from moderator.constants import DEFAULT_CONFIG
from secretballot.models import Vote

register = template.Library()


@register.inclusion_tag('moderator/inclusion_tags/report_comment_abuse.html',
                        takes_context=True)
def report_comment_abuse(context, obj):
    """
    Checks whether a user can report abuse (has not liked comment previously)
    or has reported abuse previously and renders appropriate response.

    If requesting user is part of the 'Moderators' group a vote equal to
    ABUSE_CUTOFF setting will be made, thereby immediately marking the comment
    as abusive.
    """
    request = context['request']
    is_moderator = bool(request.user.groups.filter(name='Moderators'))
    abuse_cutoff = getattr(settings, 'MODERATOR', DEFAULT_CONFIG)['ABUSE_CUTOFF']

    can_report = can_vote(obj, request.user, request)
    previously_reported = False
    if not can_report:
        previously_reported = Vote.objects.filter(
            object_id=obj.id,
            token=request.secretballot_token,
            vote__in=['-1', '-%s' % abuse_cutoff]<commit_msg>use ints, not strs<commit_after>from django import template
from django.conf import settings
from likes.utils import can_vote
from moderator.constants import DEFAULT_CONFIG
from secretballot.models import Vote

register = template.Library()


@register.inclusion_tag('moderator/inclusion_tags/report_comment_abuse.html',
                        takes_context=True)
def report_comment_abuse(context, obj):
    """
    Checks whether a user can report abuse (has not liked comment previously)
    or has reported abuse previously and renders appropriate response.

    If requesting user is part of the 'Moderators' group a vote equal to
    ABUSE_CUTOFF setting will be made, thereby immediately marking the comment
    as abusive.
    """
    request = context['request']
    is_moderator = bool(request.user.groups.filter(name='Moderators'))
    abuse_cutoff = getattr(settings, 'MODERATOR', DEFAULT_CONFIG)['ABUSE_CUTOFF']

    can_report = can_vote(obj, request.user, request)
    previously_reported = False
    if not can_report:
        previously_reported = Vote.objects.filter(
            object_id=obj.id,
            token=request.secretballot_token,
            vote__in=[-1, -1 * abuse_cutoff]
{'fraction_non_alphanumeric': 0.0779436152570481, 'fraction_numerical': 0.0012437810945273632, 'mean_word_length': 3.75, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6031607', 'n_tokens_mistral': 687, 'n_tokens_neox': 668, 'n_words': 196}