<commit_before>from django.template.defaultfilters import yesno
from django.utils.translation import pgettext_lazy

PATTERN = '%s: %s'


def handle_default(field):
    item = {
        'content': PATTERN % (field.label, field.value()),
        'name': field.name, 'value': field.value()}
    return [item]


def handle_single_choice(field, value):
    for choice_value, choice_label in field.field.choices:
        if choice_value == value:
            item = {
                'content': PATTERN % (field.label, choice_label),
                'name': field.name, 'value': value}
            return [item]
    return []


def handle_multiple_choice(field, values):
    items = []
    for value in values:
        items.extend(handle_single_choice(field, value))
    return items


def handle_single_model_choice(field, obj):
    return [{
        'content': PATTERN % (field.label, str(obj)),
        'name': field.name, 'value': obj.pk}]


def handle_multiple_model_choice(field, queryset):
    chips = []
    for obj in queryset:
        chips.extend(handle_single_model_choice(field, obj))
    return chips


def handle_nullboolean(field):
    value = yesno(
        field.value(),
        pgettext_lazy('Possible values of boolean filter', 'yes,no,all'))
    item = {
        'content': PATTERN % (field.label, value),
        'name': field.name, 'value': field.value()}
    return [item]


def handle_range(field):
    chips = []
    values = [f if f else None for f in field.value()]
    text = [
        pgettext_lazy('Label of first value in range filter', 'From'),
        pgettext_lazy('Label of second value in range filter', 'To')]
    for i, value in enumerate(values):
        if value:
            chips.append(
                {'content': PATTERN % (field.label, text[i] + ' ' + value),
                 'name': '%s_%i' % (field.name, i), 'value': field.value()[i]})
    return chips<commit_msg>Add missing import unicode_literals to chips.py<commit_after>from __future__ import unicode_literals

from django.template.defaultfilters import yesno
from django.utils.translation import pgettext_lazy

CHIPS_PATTERN = '%s: %s'


def handle_default(field):
    item = {
        'content': CHIPS_PATTERN % (field.label, field.value()),
        'name': field.name, 'value': field.value()}
    return [item]


def handle_single_choice(field, value):
    for choice_value, choice_label in field.field.choices:
        if choice_value == value:
            item = {
                'content': CHIPS_PATTERN % (field.label, choice_label),
                'name': field.name, 'value': value}
            return [item]
    return []


def handle_multiple_choice(field, values):
    items = []
    for value in values:
        items.extend(handle_single_choice(field, value))
    return items


def handle_single_model_choice(field, obj):
    return [{
        'content': CHIPS_PATTERN % (field.label, str(obj)),
        'name': field.name, 'value': obj.pk}]


def handle_multiple_model_choice(field, queryset):
    chips = []
    for obj in queryset:
        chips.extend(handle_single_model_choice(field, obj))
    return chips


def handle_nullboolean(field):
    value = yesno(
        field.value(),
        pgettext_lazy('Possible values of boolean filter', 'yes,no,all'))
    item = {
        'content': CHIPS_PATTERN % (field.label, value),
        'name': field.name, 'value': field.value()}
    return [item]


def handle_range(field):
    chips = []
    values = [f if f else None for f in field.value()]
    text = [
        pgettext_lazy('Label of first value in range filter', 'From'),
        pgettext_lazy('Label of second value in range filter', 'To')]
    for i, value in enumerate(values):
        if value:
            chips.append(
                {'content': CHIPS_PATTERN % (field.label, text[i] + ' ' + value),
                 'name': '%s_%i' % (field.name, i), 'value': field.value()[i]})
    return chips
{'fraction_non_alphanumeric': 0.1299262649377066, 'fraction_numerical': 0.0, 'mean_word_length': 2.775431861804223, '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': '3732623', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1199, 'n_words': 320}