<commit_before>from django.contrib.auth.decorators import login_required
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.conf import settings
from django.http import (HttpResponseBadRequest, HttpResponseRedirect,
                         HttpResponse, Http404)
from django.shortcuts import render, get_object_or_404
from django.template import RequestContext
from django.utils import simplejson
from django.utils.translation import ugettext as _
from django.views.decorators.http import require_POST

from tcc import api
from tcc.settings import CONTENT_TYPES
from tcc.forms import CommentForm

# jinja
from coffin.shortcuts import render_to_response
'''Monkeypatch Django to mimic Jinja2 behaviour'''
from django.utils import safestring
if not hasattr(safestring, '__html__'):
    safestring.SafeString.__html__ = lambda self: str(self)
    safestring.SafeUnicode.__html__ = lambda self: unicode(self)


def _get_tcc_index(comment):
    return reverse('tcc_index',
                   args=[comment.content_type_id, comment.object_pk])


def _get_comment_form(content_type_id, object_pk, data=None):
    if not content_type_id or int(content_type_id) not in CONTENT_TYPES:
        raise Http404()
    ct = get_object_or_404(ContentType, pk=content_type_id)
    try:
        target = ct.get_object_for_this_type(pk=object_pk)
    except ObjectDoesNotExist:
        raise Http404()
    initial = {'content_type': ct.id, 'object_pk': object_pk}
    form = CommentForm(target, data, initial=initial)
    return form


def index(request, content_type_id, object_pk):
    comments = api.get_comments_limited(
        content_type_id, object_pk
        ).extra(select={
            'sortdate': 'CASE WHEN tcc_comment.parent_id is null ' \
                ' THEN tcc_comment.submit_date ELSE T3.submit_date END'}
                ).order_by('-sortdate')
    form = _get_comment_form(content_type_id, object_pk)<commit_msg>Fix order<commit_after>from django.contrib.auth.decorators import login_required
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.conf import settings
from django.http import (HttpResponseBadRequest, HttpResponseRedirect,
                         HttpResponse, Http404)
from django.shortcuts import render, get_object_or_404
from django.template import RequestContext
from django.utils import simplejson
from django.utils.translation import ugettext as _
from django.views.decorators.http import require_POST

from tcc import api
from tcc.settings import CONTENT_TYPES
from tcc.forms import CommentForm

# jinja
from coffin.shortcuts import render_to_response
'''Monkeypatch Django to mimic Jinja2 behaviour'''
from django.utils import safestring
if not hasattr(safestring, '__html__'):
    safestring.SafeString.__html__ = lambda self: str(self)
    safestring.SafeUnicode.__html__ = lambda self: unicode(self)


def _get_tcc_index(comment):
    return reverse('tcc_index',
                   args=[comment.content_type_id, comment.object_pk])


def _get_comment_form(content_type_id, object_pk, data=None):
    if not content_type_id or int(content_type_id) not in CONTENT_TYPES:
        raise Http404()
    ct = get_object_or_404(ContentType, pk=content_type_id)
    try:
        target = ct.get_object_for_this_type(pk=object_pk)
    except ObjectDoesNotExist:
        raise Http404()
    initial = {'content_type': ct.id, 'object_pk': object_pk}
    form = CommentForm(target, data, initial=initial)
    return form


def index(request, content_type_id, object_pk):
    comments = api.get_comments_limited(
        content_type_id, object_pk
        ).extra(select={
            'sortdate': 'CASE WHEN tcc_comment.parent_id is null ' \
                ' THEN tcc_comment.submit_date ELSE T3.submit_date END'}
                ).order_by('-sortdate', 'path')
    form = _get_comment_form(content_type_id, object_pk)
{'fraction_non_alphanumeric': 0.07486499754540991, 'fraction_numerical': 0.008345606283750613, 'mean_word_length': 4.217669654289373, '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': '1399606', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1203, 'n_words': 307}