<commit_before># -*- coding: UTF-8 -*-
from assopy import models
from assopy import settings

from django import forms
from django import template
from django.conf import settings as dsettings
from django.core import paginator
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _

import urllib
from fancy_tag import fancy_tag

register = template.Library()

_field_template_standard = template.Template("""
    <div class="{{ classes }}">
        <label for="{{ field.auto_id }}">{{ field.label|safe }}{% if field.field.required %}<span class="required">{{ required_text }}</span>{% endif %}</label>
        {{ field }}
        {% if field.help_text %}<div class="help-text">{{ field.help_text|safe }}</div>{% endif %}
        {{ field.errors }}
    </div>
""")

_field_template_label_inline = template.Template("""
    <div class="{{ classes }}">
        <label for="{{ field.auto_id }}">{{ field }} {{ field.label|safe }}{% if field.field.required %}<span class="required">{{ required_text }}</span>{% endif %}</label>
        {% if field.help_text %}<div class="help-text">{{ field.help_text|safe }}</div>{% endif %}
        {{ field.errors }}
    </div>
""")

fields_template = {
    None: _field_template_standard,
    forms.widgets.CheckboxInput: _field_template_label_inline,
    forms.widgets.RadioSelect: _field_template_label_inline,
}

@register.filter()
def field(field, cls=None):
    if not hasattr(field, 'field'):
        return 'Invalid field "%r"' % field

    classes = [ 'field' ]
    if field.field.required:
        classes.append('required')
    if cls:
        classes.extend(cls.split(None))
    classes.append(field.field.__class__.__name__.lower())
    if field.errors:
        classes.append('error')

    widget = field.field.widget
    if isinstance(widget, (forms.HiddenInput,)):
        return str(field)
    else:
        try:
            tpl = fields_template[type(widget)]
        except KeyError:
            tpl = fields_template[None]<commit_msg>quando renderizzio più di un radio ho bisogno di un template da hoc, non posso metterli tutti dentro una label<commit_after># -*- coding: UTF-8 -*-
from assopy import models
from assopy import settings

from django import forms
from django import template
from django.conf import settings as dsettings
from django.core import paginator
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _

import urllib
from fancy_tag import fancy_tag

register = template.Library()

_field_template_standard = template.Template("""
    <div class="{{ classes }}">
        <label for="{{ field.auto_id }}">{{ field.label|safe }}{% if field.field.required %}<span class="required">{{ required_text }}</span>{% endif %}</label>
        {{ field }}
        {% if field.help_text %}<div class="help-text">{{ field.help_text|safe }}</div>{% endif %}
        {{ field.errors }}
    </div>
""")

_field_template_label_inline = template.Template("""
    <div class="{{ classes }}">
        <label for="{{ field.auto_id }}">{{ field }} {{ field.label|safe }}{% if field.field.required %}<span class="required">{{ required_text }}</span>{% endif %}</label>
        {% if field.help_text %}<div class="help-text">{{ field.help_text|safe }}</div>{% endif %}
        {{ field.errors }}
    </div>
""")

_field_template_input_list = template.Template("""
    <div class="{{ classes }}">
        <label>{{ field.label|safe }}{% if field.field.required %}<span class="required">{{ required_text }}</span>{% endif %}</label>
        {{ field }}
        {% if field.help_text %}<div class="help-text">{{ field.help_text|safe }}</div>{% endif %}
        {{ field.errors }}
    </div>
""")

fields_template = {
    None: _field_template_standard,
    forms.widgets.CheckboxInput: _field_template_label_inline,
    forms.widgets.RadioSelect: _field_template_input_list,
}

@register.filter()
def field(field, cls=None):
    if not hasattr(field, 'field'):
        return 'Invalid field "%r"' % field

    classes = [ 'field' ]
    if field.field.required:
        classes.append('required')
    if cls:
        classes.extend(cls.split(None))
    classes.append(field.field.__class__.__name__.lower())
    if field.errors:
        classes.append('error')

    widget = field.field.widget
    if isinstance(widget, (forms.HiddenInput,)):
        return str(field)
    else:
        try:
            tpl = fields_template[type(widget)]
        except KeyError:
            tpl = fields_template[None]
{'fraction_non_alphanumeric': 0.15556045895851722, 'fraction_numerical': 0.000441306266548985, 'mean_word_length': 3.50596421471173, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '650008', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1339, 'n_words': 337}