# Path: django_toolkit/forms/widgets.py
# class DatePickerField(AppendedText):
#     
#     def __init__(self, field, text='<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>', 
#                  css_class='dateinput dateinput-picker', extra_css_class='', 
#                  *args, **kwargs):
#         css_class += ' ' + extra_css_class
#         super(DatePickerField, self).__init__(field, text=text, 
#                                               css_class=css_class, 
#                                               *args, **kwargs)
# 
# class DateTimePickerField(AppendedText):
#     
#     def __init__(self, field, text='<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>', 
#                  css_class='datetimeinput datetimeinput-picker', extra_css_class='',
#                  *args, **kwargs):
#         css_class += ' ' + extra_css_class
#         super(DateTimePickerField, self).__init__(field, text=text, 
#                                                   css_class=css_class, 
#                                                   *args, **kwargs)
# 
# class DurationPickerField(AppendedText):
#     
#     def __init__(self, field, text='<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>', 
#                  css_class='durationinput durationinput-picker', extra_css_class='',
#                  *args, **kwargs):
#         css_class += ' ' + extra_css_class
#         super(DurationPickerField, self).__init__(field, text=text, 
#                                                   css_class=css_class,
#                                                   *args, **kwargs)


from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, TEMPLATE_PACK, Field
from django.forms.fields import DateField, DateTimeField, CharField
from durationfield.forms.fields import DurationField
from django_toolkit.forms.widgets import DatePickerField, DateTimePickerField,\
    DurationPickerField
from django.forms.forms import BoundField
from django.utils.safestring import mark_safe

class SpecialFieldsFormHelper(FormHelper):
    """
    A form helper that automatically uses DatePickerField, DateTimePickerField and DurationPickerField fields.
    """
    
    def build_default_layout(self, form):
        fields = []
        for name, field in form.fields.iteritems():
            fields.append(get_crispy_field_helper(name, field))
        return Layout(*fields)
    
    def render_layout(self, form, context, template_pack=TEMPLATE_PACK):
        self.layout = self.build_default_layout(form) 
        return super(SpecialFieldsFormHelper, self).render_layout(form, context, template_pack)

def get_crispy_field_helper(name, field):
    if isinstance(field, DateField):
        return DatePickerField(name)
    elif isinstance(field, DateTimeField):
        return DateTimePickerField(name)
    elif isinstance(field, DurationField):

# Path: django_toolkit/forms/widgets.py
# class DatePickerField(AppendedText):
#     
#     def __init__(self, field, text='<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>', 
#                  css_class='dateinput dateinput-picker', extra_css_class='', 
#                  *args, **kwargs):
#         css_class += ' ' + extra_css_class
#         super(DatePickerField, self).__init__(field, text=text, 
#                                               css_class=css_class, 
#                                               *args, **kwargs)
# 
# class DateTimePickerField(AppendedText):
#     
#     def __init__(self, field, text='<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>', 
#                  css_class='datetimeinput datetimeinput-picker', extra_css_class='',
#                  *args, **kwargs):
#         css_class += ' ' + extra_css_class
#         super(DateTimePickerField, self).__init__(field, text=text, 
#                                                   css_class=css_class, 
#                                                   *args, **kwargs)
# 
# class DurationPickerField(AppendedText):
#     
#     def __init__(self, field, text='<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>', 
#                  css_class='durationinput durationinput-picker', extra_css_class='',
#                  *args, **kwargs):
#         css_class += ' ' + extra_css_class
#         super(DurationPickerField, self).__init__(field, text=text, 
#                                                   css_class=css_class,
#                                                   *args, **kwargs)


# Path: django_toolkit/forms/crispy.py
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, TEMPLATE_PACK, Field
from django.forms.fields import DateField, DateTimeField, CharField
from durationfield.forms.fields import DurationField
from django_toolkit.forms.widgets import DatePickerField, DateTimePickerField,\
    DurationPickerField
from django.forms.forms import BoundField
from django.utils.safestring import mark_safe


class SpecialFieldsFormHelper(FormHelper):
    """
    A form helper that automatically uses DatePickerField, DateTimePickerField and DurationPickerField fields.
    """
    
    def build_default_layout(self, form):
        fields = []
        for name, field in form.fields.iteritems():
            fields.append(get_crispy_field_helper(name, field))
        return Layout(*fields)
    
    def render_layout(self, form, context, template_pack=TEMPLATE_PACK):
        self.layout = self.build_default_layout(form) 
        return super(SpecialFieldsFormHelper, self).render_layout(form, context, template_pack)

def get_crispy_field_helper(name, field):
    if isinstance(field, DateField):
        return DatePickerField(name)
    elif isinstance(field, DateTimeField):
        return DateTimePickerField(name)
    elif isinstance(field, DurationField):

        return DurationPickerField(name)