class Callout(crispy_forms_layout.Div):
    """
    Act like ``Div`` but add a ``callout`` class name.

    Example:

    .. sourcecode:: python

        Callout('form_field_1', 'form_field_2', css_id='div-example',
              css_class='divs')
    """
    def __init__(self, field, *args, **kwargs):
        kwargs['css_class'] = kwargs.get('css_class', '')+' callout'
        super(Callout, self).__init__(field, *args, **kwargs) class Layout(crispy_forms_layout.Layout):
    pass class HTML(crispy_forms_layout.HTML):
    pass class Row(Div):
    """
    Wrap fields in a div whose default class is ``row``. Example:

    .. sourcecode:: python

        Row('form_field_1', 'form_field_2', 'form_field_3')

    Act as a div container row, it will embed its items in a div like that:

    .. sourcecode:: html

        <div class"row">Content</div>
    """
    css_class = 'row' class Column(Div):
    """
    Wrap fields in a div. If not defined, CSS class will default to
    ``large-12 columns``. ``columns`` class is always appended, so you don't
    need to specify it.

    This is the column from the Foundation Grid component, all columns should
    be contained in a **Row** or a **RowFluid** and you will have to define the
    column type in the ``css_class`` attribute.

    Example:

    .. sourcecode:: python

        Column('form_field_1', 'form_field_2', css_class='small-12 large-6')

    Will render to something like that:

    .. sourcecode:: html

        <div class"small-12 large-6 columns">...</div>

    ``columns`` class is always appended, so you don't need to specify it.

    If not defined, ``css_class`` will default to ``large-12``.
    """
    css_class = 'columns'

    def __init__(self, field, *args, **kwargs):
        self.field = field
        if 'css_class' not in kwargs:
            kwargs['css_class'] = 'large-12'

        super(Column, self).__init__(field, *args, **kwargs) class InlineField(Field):
    """
    Layout object for rendering an inline field with Foundation

    Example:

    .. sourcecode:: python

        InlineField('field_name')

    Or:

    .. sourcecode:: python

        InlineField('field_name', label_column='large-8',
                    input_column='large-4', label_class='')

    ``label_column``, ``input_column``, ``label_class``, are optional argument.
    """
    template = "%s/layout/inline_field.html"

    def __init__(self, field, label_column='large-3', input_column='large-9',
                 label_class='', *args, **kwargs):
        self.field = field
        self.label_column = label_column+' columns'
        self.input_column = input_column+' columns'
        self.label_class = label_class

        super(InlineField, self).__init__(field, *args, **kwargs)

    def render(self, form, form_style, context, template_pack=TEMPLATE_PACK):
        context['label_column'] = self.label_column
        context['input_column'] = self.input_column
        context['label_class'] = self.label_class

        html = ''
        template = self.get_template_name(template_pack)
        for field in self.fields:
            html += render_field(field, form, form_style, context,
                                 template=template, attrs=self.attrs,
                                 template_pack=template_pack)
        return html class InlineJustifiedField(InlineField):
    """
    Same as InlineField but default is to be right aligned with a vertical
    padding
    """
    def __init__(self, field, *args, **kwargs):
        default = 'middle text-right inline'
        kwargs['label_class'] = kwargs.get('label_class', None) or default
        super(InlineJustifiedField, self).__init__(field, *args, **kwargs) class SwitchField(Field):
    """
    A specific field to use Foundation form switches

    You must only use this with a checkbox field and this is a *raw* usage of
    this Foundation element, you should see ``InlineSwitchField`` instead.

    Example:

    .. sourcecode:: python

        SwitchField('field_name', style="color: #333;", css_class="whatever",
                    id="field_name")
    """
    template = "%s/switch.html"

    def __init__(self, field, *args, **kwargs):
        self.switch_class = ['switch'] + kwargs.pop('switch_class', '').split()
        kwargs['class'] = (kwargs.pop('class', '') + ' switch-input').strip()

        super(SwitchField, self).__init__(field, *args, **kwargs)

    def render(self, form, form_style, context, template_pack=TEMPLATE_PACK):
        context['switch_class'] = " ".join(self.switch_class)
        return super(SwitchField, self).render(form, form_style, context,
                                               template_pack) class InlineSwitchField(InlineField):
    """
    Like ``SwitchField`` it use Foundation form switches with checkbox field
    but within an ``InlineField``

    Contrary to ``SwitchField`` this play nice with the label to be able to
    display it (as Foundation form switches default behavior is to hide the
    label text)

    Example:

    .. sourcecode:: python

        InlineSwitchField('field_name')

    Or:

    .. sourcecode:: python

        InlineSwitchField('field_name', label_column='large-8',
                          input_column='large-4', label_class='',
                          switch_class="inline")

    ``label_column``, ``input_column``, ``label_class``, ``switch_class`` are
    optional argument.
    """
    template = "%s/inline_switch.html"

    def __init__(self, field, *args, **kwargs):
        self.switch_class = ['switch']+kwargs.pop('switch_class', '').split()
        kwargs['label_column'] = kwargs.pop('label_column', 'large-8')
        kwargs['input_column'] = kwargs.pop('input_column', 'large-4')
        kwargs['class'] = (kwargs.pop('class', '') + ' switch-input').strip()

        super(InlineSwitchField, self).__init__(field, *args, **kwargs)

    def render(self, form, form_style, context, template_pack=TEMPLATE_PACK):
        context['switch_class'] = " ".join(self.switch_class)
        return super(InlineSwitchField, self).render(form, form_style, context,
                                                     template_pack) class ButtonHolder(crispy_forms_layout.ButtonHolder):
    """
    It wraps fields in an element ``<div class="button-holder">``.

    This is where you should put Layout objects that render to form buttons
    like Submit. It should only hold ``HTML`` and ``BaseInput`` inherited
    objects.

    Example:

    .. sourcecode:: python

        ButtonHolder(
            HTML(<span style="display: hidden;">Information Saved</span>),
            Submit('Save', 'Save')
        )
    """
    template = "%s/layout/buttonholder.html" class ButtonGroup(crispy_forms_layout.LayoutObject):
    """
    It wraps fields in an element ``<div class="button-group">``.

    This is where you should put Layout objects that render to form buttons
    like Submit. It should only hold `HTML` and `BaseInput` inherited objects.

    Example:

    .. sourcecode:: python

        ButtonGroup(
            Submit('Save', 'Save'),
            Button('Cancel', 'Cancel'),
        )
    """
    template = "%s/layout/buttongroup.html"

    def __init__(self, *fields, **kwargs):
        self.fields = list(fields)
        self.css_class = kwargs.get('css_class', None)
        self.css_id = kwargs.get('css_id', None)
        self.template = kwargs.get('template', self.template)

    def render(self, form, form_style, context, template_pack=TEMPLATE_PACK):
        field_list = []
        template = self.get_template_name(template_pack)

        for field in self.fields:
            field_list.append(
                render_field(field, form, form_style, context,
                             template_pack=template_pack)
            )

        buttons = render_to_string(template, {
            'buttongroup': self,
            'field_list': field_list,
        })

        return buttons class Button(InputButton):
    """
    This is the old Button object that inherit from ``InputButton`` for
    backward compatibility.

    If you want to stand for an input button, you are invited to use
    ``InputButton`` instead to avoid problem when ``ButtonElement`` will
    become the new ``Button`` object.
    """
    pass class Submit(InputSubmit):
    """
    This is the old Button object that inherit from ``InputSubmit`` for
    backward compatibility.

    If you want to stand for an input button, you are invited to use
    ``InputSubmit`` instead to avoid problem when ``ButtonSubmit`` will
    become the new ``Submit`` object.
    """
    pass class Reset(InputReset):
    """
    This is the old Button object that inherit from ``InputReset`` for
    backward compatibility.

    If you want to stand for an input button, you are invited to use
    ``InputReset`` instead to avoid problem when ``ButtonReset`` will
    become the new ``Reset`` object.
    """
    pass class ButtonElement(crispy_forms_layout.BaseInput):
    """
    Contrary to ``Button``, ButtonElement purpose use a ``<button>`` element
    to create a clickable form button and accept an argument to add free
    content inside element.

    Advantage of ``<button>`` is to accept almost any HTML content inside
    element.

    .. sourcecode:: python

        button = ButtonElement('name', 'value',
                               content="<span>Press Me!</span>")

    .. note::
            * First argument is for ``name`` attribute and also turned into
              the id for the button;
            * Second argument is for ``value`` attribute and also for element
              content if not given;
            * Third argument is an optional named argument ``content``, if
              given it will be appended inside element instead of ``value``.
              Content string is marked as safe so you can put anything you
              want;
    """
    template = "%s/layout/basebutton.html"
    input_type = 'button'
    field_classes = 'button'

    def __init__(self, field, *args, **kwargs):
        self.content = kwargs.pop('content', None)
        super(ButtonElement, self).__init__(field, *args, **kwargs)

    def render(self, form, form_style, context, template_pack=TEMPLATE_PACK):
        context['button_content'] = self.content
        return super(ButtonElement, self).render(form, form_style, context,
                                                 template_pack) class ButtonSubmit(ButtonElement):
    """
    Create a submit button following the ``ButtonElement`` behaviors:

    .. sourcecode:: python

        button = ButtonSubmit('search', 'go-search',
                              content="<span>Search this site!</span>")

    """
    input_type = 'submit'
    field_classes = 'submit button' class ButtonReset(ButtonElement):
    """
    Create a reset button following the ``ButtonElement`` behaviors:

    .. sourcecode:: python

        button = ButtonReset('reset', 'revert'
                             content="<span>Revert Me!</span>")

    """
    input_type = 'reset'
    field_classes = 'reset button' class Fieldset(crispy_forms_layout.Fieldset):
    """
    It wraps fields in a ``<fieldset>``:

    .. sourcecode:: python

        Fieldset("Text for the legend",
            'form_field_1',
            'form_field_2'
        )

    The first parameter is the text for the fieldset legend. This text is
    context aware, so you can do things like :

    .. sourcecode:: python

        Fieldset("Data for {{ user.username }}",
            'form_field_1',
            'form_field_2'
        )
    """
    template = "%s/layout/fieldset.html"
from django.utils.translation import gettext_lazy as _
from crispy_forms.helper import FormHelper
from crispy_forms_foundation.layout import (
    Layout, Fieldset, HTML, Row, Column, Callout,
    ButtonHolder, ButtonGroup,
    Button, Submit, Reset,
    ButtonElement, ButtonSubmit, ButtonReset,
    InlineField, InlineJustifiedField,
    SwitchField, InlineSwitchField
)
"""
Forms crispies items
"""


def part_1_crispies(pack=None):
    return [
        Row(
            Column('full_input'),
        ),
        Row(
            Column(
                Row(
                    Column(
                        'column_input_1',
                        css_class='large-4'
                    ),
                    Column(
                        'column_input_2',
                        css_class='large-4'
                    ),
                    Column(
                        'column_input_3',
                        css_class='large-4'
                    ),
                )
            ),
        ),
    ]


def part_2_crispies(pack=None):
    return [
        Row(
            Column(
                'select_input',
                css_class='large-12'
            ),
        ),
        Row(
            Column(
                'radio_input',
                css_class='large-4'
            ),
            Column(
                'checkbox_input',
                css_class='large-4'
            ),
            Column(
                Row(
                    Column(
                        SwitchField('checkbox_switch_input_1', switch_class="round tiny"),
                        css_class='small-3'
                    ),
                    Column(
                        HTML('<label>Checkbox with a switch field</label>'),
                        css_class='small-9'
                    ),
                ),
                Row(
                    Column(
                        InlineSwitchField('checkbox_switch_input_2'),
                    ),
                ),
                css_class='large-4'
            ),
        ),
    ]


def part_3_crispies(pack=None):
    return [
        Row(
            Column('textarea_input'),
        ),
    ]


def part_4_crispies(pack=None):
    return [
        InlineField('inlinefield_input'),
        InlineJustifiedField('inlinejustifiedfield_input'),
    ]


def buttons_crispies(pack=None):
    return [
        Row(
            Column(
                ButtonGroup(
                    Submit('submit', _('Submit'), css_class='success'),
                    Reset('cancel', _('Cancel')),
                    Button('dummy', _('Delete'), css_class='alert'),
                    css_class='radius right'
                ),
                css_class='clearfix'
            ),
        ),
        Row(
            Column(
                Callout(
                    HTML("""<p>As &lt;input/&gt;</p>"""),
                    ButtonGroup(
                        Submit('submit', _('Submit'), css_class='success'),
                        Reset('cancel', _('Cancel')),
                        Button('dummy', _('Delete'), css_class='alert'),
                        css_class='radius right'
                    ),
                    css_class='clearfix'
                )
            ),
        ),
        Row(
            Column(

                Callout(