<commit_before>from ella.ellacomments.models import CommentOptionsObject, CommentIPBlocklist
import operator

from django.contrib import comments
from django.contrib.comments import signals
from django.contrib.comments.views.comments import CommentPostBadRequest
from django.utils.html import escape
from django.utils.translation import ugettext as _
from django.template.defaultfilters import slugify
from django.template import RequestContext
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseRedirect, Http404
from django.db.models import Q
from django.db import transaction
from django.core.paginator import Paginator
from django.conf import settings

from ella.core.views import get_templates_from_placement

@transaction.commit_on_success
def post_comment(request, context, parent_id=None):
    'Mostly copy-pasted from django.contrib.comments.views.comments'
    opts = CommentOptionsObject.objects.get_for_object(context['object'])
    if opts.blocked:
        raise Http404('Comments is blocked for this object.')

    parent = None
    if parent_id:
        parent = get_object_or_404(comments.get_model(), pk=parent_id)

    if request.method != 'POST':
        initial = {}
        if parent:
            if parent.title.startswith('Re:'):
                initial['title'] = parent.title
            else:
                initial['title'] = u'Re: %s' % parent.title
        form = comments.get_form()(context['object'], parent=parent_id, initial=initial)
        context.update({
                'parent': parent,
                'form': form,
            })
        return render_to_response(
            get_templates_from_placement('comment_form.html', context['placement']),
            context,
            RequestContext(request)
        )

    ip_address = request.META.get('REMOTE_ADDR', None)
    if ip_address and CommentIPBlocklist.objects.filter(ip_address=ip_address).count():
        raise Http404('Your IP address is banned from commenting.')

    # Fill out some initial data fields from an authenticated user, if present
    data = request.POST.copy()

    if request.user.is_authenticated():
        if not data.get('name', ''):
            data["name"] = request.user.get_full_name() or request.user.username
        if not data.get('email', ''):
            data["email"] = request.user.email

    # construct the form
    form = comments.get_form()(context['object'], data=data, parent=parent_id)

    # Check security information
    if form.security_errors():<commit_msg>Being nice to banned users, letting them know. Refs #7595<commit_after>from ella.ellacomments.models import CommentOptionsObject, CommentIPBlocklist
import operator

from django.contrib import comments
from django.contrib.comments import signals
from django.contrib.comments.views.comments import CommentPostBadRequest
from django.utils.html import escape
from django.utils.translation import ugettext as _
from django.template.defaultfilters import slugify
from django.template import RequestContext
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseRedirect, Http404
from django.db.models import Q
from django.db import transaction
from django.core.paginator import Paginator
from django.conf import settings

from ella.core.views import get_templates_from_placement

@transaction.commit_on_success
def post_comment(request, context, parent_id=None):
    'Mostly copy-pasted from django.contrib.comments.views.comments'
    opts = CommentOptionsObject.objects.get_for_object(context['object'])
    if opts.blocked:
        raise Http404('Comments is blocked for this object.')

    parent = None
    if parent_id:
        parent = get_object_or_404(comments.get_model(), pk=parent_id)

    ip_address = request.META.get('REMOTE_ADDR', None)
    try:
        ip_ban = CommentIPBlocklist.objects.get(ip_address=ip_address)
    except CommentIPBlocklist.DoesNotExist:
        ip_ban = None

    if request.method != 'POST':
        initial = {}
        if parent:
            if parent.title.startswith('Re:'):
                initial['title'] = parent.title
            else:
                initial['title'] = u'Re: %s' % parent.title
        form = comments.get_form()(context['object'], parent=parent_id, initial=initial)
        context.update({
                'parent': parent,
                'form': form,
                'ip_ban': ip_ban,
            })
        return render_to_response(
            get_templates_from_placement('comment_form.html', context['placement']),
            context,
            RequestContext(request)
        )

    # Fill out some initial data fields from an authenticated user, if present
    data = request.POST.copy()

    if request.user.is_authenticated():
        if not data.get('name', ''):
            data["name"] = request.user.get_full_name() or request.user.username
        if not data.get('email', ''):
            data["email"] = request.user.email

    # construct the form
    form = comments.get_form()(context['object'], data=data, parent=parent_id)

    # Check security information
    if form.security_errors():
{'fraction_non_alphanumeric': 0.09390667180871577, 'fraction_numerical': 0.005977632086386425, 'mean_word_length': 3.311720698254364, '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': '2069878', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1376, 'n_words': 361}