<commit_before>from urlparse import urlsplit, urlunsplit, urlparse

from django import template
from django.http.request import QueryDict

from django.template.defaultfilters import floatformat
from django.contrib.humanize.templatetags.humanize import intcomma

from ..models import GERMAN_STATES_DICT

register = template.Library()


def get_state_name(context, key):
    return GERMAN_STATES_DICT.get(key, '')


def parse_query(query_string):
    return QueryDict(query_string.encode('ascii', 'ignore'), mutable=True)


DECIMAL_SEPARATOR = floatformat(0.0, 2)[1]


def add_embed(url):
    (scheme, netloc, path, query, fragment) = urlsplit(url)
    d = parse_query(query)
    d['embed'] = '1'
    query = d.urlencode()
    return urlunsplit((scheme, netloc, path, query, fragment))


def intcomma_floatformat(value, arg):
    val = intcomma(value)
    if DECIMAL_SEPARATOR not in val:
        val += '%s00' % DECIMAL_SEPARATOR
    else:
        before_comma, after_comma = val.rsplit(DECIMAL_SEPARATOR, 1)
        if len(after_comma) == 0:
            after_comma = '00'
        elif len(after_comma) == 1:
            after_comma += '0'
        val = '%s%s%s' % (before_comma, DECIMAL_SEPARATOR, after_comma)
    return val


def facet_active(context, name, value=None):
    request = context['request']
    d = parse_query(urlparse(request.get_full_path()).query)

    if value is None:
        return d.get(name, '')

    value = unicode(value)
    if d.get(name, '') == value:<commit_msg>Put decimal separator detection into function<commit_after>from urlparse import urlsplit, urlunsplit, urlparse

from django import template
from django.http.request import QueryDict

from django.template.defaultfilters import floatformat
from django.contrib.humanize.templatetags.humanize import intcomma

from ..models import GERMAN_STATES_DICT

register = template.Library()


def get_state_name(context, key):
    return GERMAN_STATES_DICT.get(key, '')


def parse_query(query_string):
    return QueryDict(query_string.encode('ascii', 'ignore'), mutable=True)


def add_embed(url):
    (scheme, netloc, path, query, fragment) = urlsplit(url)
    d = parse_query(query)
    d['embed'] = '1'
    query = d.urlencode()
    return urlunsplit((scheme, netloc, path, query, fragment))


def intcomma_floatformat(value, arg):
    DECIMAL_SEPARATOR = floatformat(0.0, 2)[1]

    val = intcomma(value)
    if DECIMAL_SEPARATOR not in val:
        val += '%s00' % DECIMAL_SEPARATOR
    else:
        before_comma, after_comma = val.rsplit(DECIMAL_SEPARATOR, 1)
        if len(after_comma) == 0:
            after_comma = '00'
        elif len(after_comma) == 1:
            after_comma += '0'
        val = '%s%s%s' % (before_comma, DECIMAL_SEPARATOR, after_comma)
    return val


def facet_active(context, name, value=None):
    request = context['request']
    d = parse_query(urlparse(request.get_full_path()).query)

    if value is None:
        return d.get(name, '')

    value = unicode(value)
    if d.get(name, '') == value:
{'fraction_non_alphanumeric': 0.11445583857095601, 'fraction_numerical': 0.008600727753886867, 'mean_word_length': 3.7772511848341233, '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': '5758986', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1019, 'n_words': 236}