<commit_before># -*- coding: utf-8
from django import template
from django.template import RequestContext
from django.utils.encoding import smart_unicode
from django.db import settings

register = template.Library()

# TODO: this old code requires refactoring
@register.inclusion_tag('common/pagination.html',takes_context=True)
def pagination(context, adjacent_pages=5):
    """
    Return the list of A tags with links to pages.
    """

    page_list = range(
        max(1,context['page'] - adjacent_pages),
        min(context['pages'],context['page'] + adjacent_pages) + 1)
    lower_page = None
    higher_page = None

    if not 1 == context['page']:
        lower_page = context['page'] - 1

    if not 1 in page_list:
        page_list.insert(0,1)
        if not 2 in page_list:
            page_list.insert(1,'.')

    if not context['pages'] == context['page']:
        higher_page = context['page'] + 1

    if not context['pages'] in page_list:
        if not context['pages'] - 1 in page_list:
            page_list.append('.')
        page_list.append(context['pages'])
    get_params = '&'.join(['%s=%s' % (x[0],','.join(x[1])) for x in
        context['request'].GET.iteritems() if (not x[0] == 'page' and not x[0] == 'per_page')])
    if get_params:
        get_params = '?%s&' % get_params
    else:
        get_params = '?'

    return {
        'get_params': get_params,
        'lower_page': lower_page,
        'higher_page': higher_page,
        'page': context['page'],
        'pages': context['pages'],
        'page_list': page_list,
        'per_page': context['per_page'],
        }


@register.inclusion_tag('common/link.html')
def link(object, anchor=u''):
    """
    Return A tag with link to object.
    """

    user_id = None
    url = hasattr(object,'get_absolute_url') and object.get_absolute_url() or ''
    anchor = anchor or smart_unicode(object)
    return {'user_id': user_id,
            'url': url,
            'anchor': anchor}


@register.inclusion_tag('common/field_as_p.html')
def field_as_p(form, field_name):
    return {
        'errors': form.errors.get(field_name,[]),
        'field': form[field_name]}


@register.filter
def strong_spaces(string):
    return string.replace(u' ',u'&nbsp;')
<commit_msg>fix escaping in strong_spaces filter<commit_after># -*- coding: utf-8
from django import template
from django.template import RequestContext
from django.utils.encoding import smart_unicode
from django.db import settings
from django.utils.safestring import mark_safe

register = template.Library()

# TODO: this old code requires refactoring
@register.inclusion_tag('common/pagination.html',takes_context=True)
def pagination(context, adjacent_pages=5):
    """
    Return the list of A tags with links to pages.
    """

    page_list = range(
        max(1,context['page'] - adjacent_pages),
        min(context['pages'],context['page'] + adjacent_pages) + 1)
    lower_page = None
    higher_page = None

    if not 1 == context['page']:
        lower_page = context['page'] - 1

    if not 1 in page_list:
        page_list.insert(0,1)
        if not 2 in page_list:
            page_list.insert(1,'.')

    if not context['pages'] == context['page']:
        higher_page = context['page'] + 1

    if not context['pages'] in page_list:
        if not context['pages'] - 1 in page_list:
            page_list.append('.')
        page_list.append(context['pages'])
    get_params = '&'.join(['%s=%s' % (x[0],','.join(x[1])) for x in
        context['request'].GET.iteritems() if (not x[0] == 'page' and not x[0] == 'per_page')])
    if get_params:
        get_params = '?%s&' % get_params
    else:
        get_params = '?'

    return {
        'get_params': get_params,
        'lower_page': lower_page,
        'higher_page': higher_page,
        'page': context['page'],
        'pages': context['pages'],
        'page_list': page_list,
        'per_page': context['per_page'],
        }


@register.inclusion_tag('common/link.html')
def link(object, anchor=u''):
    """
    Return A tag with link to object.
    """

    user_id = None
    url = hasattr(object,'get_absolute_url') and object.get_absolute_url() or ''
    anchor = anchor or smart_unicode(object)
    return {'user_id': user_id,
            'url': url,
            'anchor': anchor}


@register.inclusion_tag('common/field_as_p.html')
def field_as_p(form, field_name):
    return {
        'errors': form.errors.get(field_name,[]),
        'field': form[field_name]}


@register.filter
def strong_spaces(text):
    return mark_safe(text.replace(u' ',u'&nbsp;'))

{'fraction_non_alphanumeric': 0.14664926022628372, 'fraction_numerical': 0.0073977371627502175, 'mean_word_length': 3.0148471615720522, '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': '7642196', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1458, 'n_words': 352}