<commit_before>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4


import math
from django import template
register = template.Library()

# when this module is imported via {% load paginator_tags %}, it is
# imported as django.templatetags.paginator_tags, which prevents a
# relative import (..conf) to rapidsms from working here. in fact, that
# would import django.conf, so it will appear to be working, but per-app
# settings won't work! PAGINATOR_ defaults are in the ..settings module.
from rapidsms.conf import settings


@register.inclusion_tag("rapidsms/templatetags/paginator.html", takes_context=True)
def paginator(context, page, prefix=""):

    dom_id = prefix + "paginator"
    page_param = prefix + "page"
    request = context["request"]

    def _link(page_number):
        return _self_link(request, **{page_param: page_number})

    def _page(number):
        return {
            "number": number,
            "link": _link(number),
            "active": (page.number == number)}

    #border_links represent the first N pages and last N pages in the paginator
    border_links = min(settings.PAGINATOR_BORDER_LINKS, page.paginator.num_pages)
    #adjacent_links represents the N pages around the current page
    adjacent_links = min(settings.PAGINATOR_ADJACENT_LINKS, page.paginator.num_pages)
    last_page_number = page.paginator.num_pages + 1

    pages = {page.number}
    #first set of border links
    for p in range(1, border_links + 1):
        pages.add(p)
    #last border links
    for p in range(last_page_number - border_links, last_page_number):
        pages.add(p)
    #make sure that the adjacent links do not go outside of the page range
    first_adjacent = max(1, page.number - adjacent_links)
    last_adjacent = min(page.number + adjacent_links + 1, last_page_number)
    for p in range(first_adjacent, last_adjacent):
        pages.add(p)
<commit_msg>Fix set syntax for python <2.7<commit_after>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4


import math
from django import template
register = template.Library()

# when this module is imported via {% load paginator_tags %}, it is
# imported as django.templatetags.paginator_tags, which prevents a
# relative import (..conf) to rapidsms from working here. in fact, that
# would import django.conf, so it will appear to be working, but per-app
# settings won't work! PAGINATOR_ defaults are in the ..settings module.
from rapidsms.conf import settings


@register.inclusion_tag("rapidsms/templatetags/paginator.html", takes_context=True)
def paginator(context, page, prefix=""):

    dom_id = prefix + "paginator"
    page_param = prefix + "page"
    request = context["request"]

    def _link(page_number):
        return _self_link(request, **{page_param: page_number})

    def _page(number):
        return {
            "number": number,
            "link": _link(number),
            "active": (page.number == number)}

    #border_links represent the first N pages and last N pages in the paginator
    border_links = min(settings.PAGINATOR_BORDER_LINKS, page.paginator.num_pages)
    #adjacent_links represents the N pages around the current page
    adjacent_links = min(settings.PAGINATOR_ADJACENT_LINKS, page.paginator.num_pages)
    last_page_number = page.paginator.num_pages + 1

    pages = set([page.number])
    #first set of border links
    for p in range(1, border_links + 1):
        pages.add(p)
    #last border links
    for p in range(last_page_number - border_links, last_page_number):
        pages.add(p)
    #make sure that the adjacent links do not go outside of the page range
    first_adjacent = max(1, page.number - adjacent_links)
    last_adjacent = min(page.number + adjacent_links + 1, last_page_number)
    for p in range(first_adjacent, last_adjacent):
        pages.add(p)

{'fraction_non_alphanumeric': 0.09276729559748427, 'fraction_numerical': 0.0047169811320754715, 'mean_word_length': 3.6266666666666665, 'pattern_counts': {'":': 6, '<': 4, '<?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': '5094023', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1171, 'n_words': 371}