<commit_before>from ddh_utils.utils import PaginationDisplay
from django import template

register = template.Library()


@register.inclusion_tag("includes/pagination.html")
def display_pagination(qd, page):
    """Includes a template displaying a full pagination listing in the
    context of `page`.

    :param qd: query paramters to base URLs on
    :type qd: `django.http.QueryDict`
    :param page: context page of a set of paginated results
    :type page: `django.core.paginator.Page`
    :rtype: `dict`

    """
    pd = PaginationDisplay(qd)
    return {"data": pd.generate_data(page)}


@register.simple_tag
def add_facet_link(qd, facet, value):
    """Returns a URL with `facet` and its `value` added to the query
    parameters in `qd`.

    :param qd: query paramters to base URLs on
    :type qd: `django.http.QueryDict`pass
    :param facet: name of facet to add
    :type facet: `str`
    :param value: value of facet to add
    :type value: `str`
    :rtype: `str`

    """
    qd = qd.copy()
    qd["page"] = 1
    if "printme" in qd:
        del qd["printme"]
    facets = qd.getlist("selected_facets", [])
    if len(facet) > 0:
        facet_value = "{0}_exact:{1}".format(facet, value.encode("utf-8"))
        if facet_value not in facets:
            facets.append(facet_value)
            qd.setlist("selected_facets", facets)
    return "?{0}".format(qd.urlencode())


@register.simple_tag
def remove_facet_link(qd, facet):
    """Returns a URL with `facet` removed from the query parameters in
    `qd`.

    :param qd: query paramters to base URLs on
    :type qd: `django.http.QueryDict`pass<commit_msg>removed superflous encoding in tag<commit_after>from ddh_utils.utils import PaginationDisplay
from django import template

register = template.Library()


@register.inclusion_tag("includes/pagination.html")
def display_pagination(qd, page):
    """Includes a template displaying a full pagination listing in the
    context of `page`.

    :param qd: query paramters to base URLs on
    :type qd: `django.http.QueryDict`
    :param page: context page of a set of paginated results
    :type page: `django.core.paginator.Page`
    :rtype: `dict`

    """
    pd = PaginationDisplay(qd)
    return {"data": pd.generate_data(page)}


@register.simple_tag
def add_facet_link(qd, facet, value):
    """Returns a URL with `facet` and its `value` added to the query
    parameters in `qd`.

    :param qd: query paramters to base URLs on
    :type qd: `django.http.QueryDict`pass
    :param facet: name of facet to add
    :type facet: `str`
    :param value: value of facet to add
    :type value: `str`
    :rtype: `str`

    """
    qd = qd.copy()
    qd["page"] = 1
    if "printme" in qd:
        del qd["printme"]
    facets = qd.getlist("selected_facets", [])
    if len(facet) > 0:
        facet_value = "{0}_exact:{1}".format(facet, value)
        if facet_value not in facets:
            facets.append(facet_value)
            qd.setlist("selected_facets", facets)
    return "?{0}".format(qd.urlencode())


@register.simple_tag
def remove_facet_link(qd, facet):
    """Returns a URL with `facet` removed from the query parameters in
    `qd`.

    :param qd: query paramters to base URLs on
    :type qd: `django.http.QueryDict`pass
{'fraction_non_alphanumeric': 0.1174671153257877, 'fraction_numerical': 0.00336494340776996, 'mean_word_length': 3.2412451361867705, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, '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': '918947', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1079, 'n_words': 335}