from django.forms import widgets
from django.utils.translation import ugettext_lazy as _


# set various html attributes to enrich date fields and the like
# with some jquery magic
def pimp_form_fields(form):
    # for field in form:

    convert_types = [widgets.TextInput, widgets.EmailInput, widgets.Textarea, widgets.CheckboxInput,
                     widgets.RadioSelect,
                     widgets.FileInput, widgets.ClearableFileInput, widgets.NumberInput, widgets.PasswordInput]

    for field in form:
        if isinstance(field.field.widget, widgets.Select) \
                and not isinstance(field.field.widget, widgets.RadioSelect):
            # chosen plugin needs an empty first entry to display the placeholder
            field.field.empty_label = ' '
            field.field.widget.attrs['data-placeholder'] = 'select an entry'
            field.field.widget.attrs['class'] = 'select2'
            field.field.widget.attrs['style'] = 'width:200px;'

        if type(field.field.widget) in convert_types:
            # let the metro plugin do its magic
            field.field.widget.attrs['data-transform'] = 'input-control'

        field.field.widget.attrs['placeholder'] = field.label

    return form


from django.core.urlresolvers import reverse


def list_breadcrumb(url_name, model_class):
    return {
        'url': reverse(url_name),
        'label': model_class._meta.verbose_name_plural
    }


def default_detail_crumb(url_name, model_instance):
    return {
        'url': reverse(url_name, kwargs={'pk': model_instance.pk}),
        'label': model_instance
    }


def add_breadcrumb():
    return {
        'url': '#',
        'label': _('create')
    }


def edit_breadcrumb():
    return {
        'url': '#',
        'label': _('update')
    }