<commit_before>"""
Button layout items

See :

* `Foundation buttons <http://foundation.zurb.com/docs/components/buttons.html>`_ for button components;
* `Foundation button groups <http://foundation.zurb.com/docs/components/button_groups.html>`_ for button groups components;
"""
from django.conf import settings
from django.template import Context
from django.template.loader import render_to_string

from crispy_forms.utils import render_field
from crispy_forms import layout as crispy_forms_layout

TEMPLATE_PACK = getattr(settings, 'CRISPY_TEMPLATE_PACK', 'foundation-5')

class ButtonHolder(crispy_forms_layout.ButtonHolder):
    """
    It wraps fields in a ``<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 = "{0}/layout/buttonholder.html".format(TEMPLATE_PACK)


class ButtonHolderPanel(ButtonHolder):
    """
    Act like ``ButtonHolder`` but add a ``panel`` css class on the main div
    """
    def __init__(self, field, *args, **kwargs):
        kwargs['css_class'] = kwargs.get('css_class', '')+' panel'
        super(ButtonHolderPanel, self).__init__(field, *args, **kwargs)


class ButtonGroup(crispy_forms_layout.LayoutObject):
    """
    It wraps fields in a ``<ul 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 = "{0}/layout/buttongroup.html".format(TEMPLATE_PACK)

    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 = []
        for field in self.fields:
            field_list.append(
                render_field(field, form, form_style, context, template_pack=template_pack)
            )

        return render_to_string(self.template, Context({'buttongroup': self, 'field_list': field_list}))


class Button(crispy_forms_layout.Button):
    """
    Used to create a Submit input descriptor for the {% crispy %} template tag:

    .. sourcecode:: python

        button = Button('Button 1', 'Press Me!')

    .. note:: The first argument is also slugified and turned into the id for the button.
    """
    input_type = 'button'
    field_classes = 'button'


class Submit(crispy_forms_layout.Submit):
    """
    Used to create a Submit button descriptor for the {% crispy %} template tag:

    .. sourcecode:: python

        submit = Submit('Search the Site', 'search this site')

    .. note:: The first argument is also slugified and turned into the id for the submit button.
    """
    input_type = 'submit'
    field_classes = 'submit button'


class Hidden(crispy_forms_layout.Hidden):
    """
    Used to create a Hidden input descriptor for the {% crispy %} template tag.
    """
    input_type = 'hidden'
    field_classes = 'hidden'


class Reset(crispy_forms_layout.Reset):
    """
    Used to create a Reset button input descriptor for the {% crispy %} template tag:

    .. sourcecode:: python

        reset = Reset('Reset This Form', 'Revert Me!')

    .. note:: The first argument is also slugified and turned into the id for the reset.
    """
    input_type = 'reset'
    field_classes = 'reset button'<commit_msg>Issue #25  subclass BaseInput instead of buttons.<commit_after>"""
Button layout items

See :

* `Foundation buttons <http://foundation.zurb.com/docs/components/buttons.html>`_ for button components;
* `Foundation button groups <http://foundation.zurb.com/docs/components/button_groups.html>`_ for button groups components;
"""
from django.conf import settings
from django.template import Context
from django.template.loader import render_to_string

from crispy_forms.utils import render_field
from crispy_forms import layout as crispy_forms_layout

TEMPLATE_PACK = getattr(settings, 'CRISPY_TEMPLATE_PACK', 'foundation-5')

class ButtonHolder(crispy_forms_layout.ButtonHolder):
    """
    It wraps fields in a ``<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 = "{0}/layout/buttonholder.html".format(TEMPLATE_PACK)


class ButtonHolderPanel(ButtonHolder):
    """
    Act like ``ButtonHolder`` but add a ``panel`` css class on the main div
    """
    def __init__(self, field, *args, **kwargs):
        kwargs['css_class'] = kwargs.get('css_class', '')+' panel'
        super(ButtonHolderPanel, self).__init__(field, *args, **kwargs)


class ButtonGroup(crispy_forms_layout.LayoutObject):
    """
    It wraps fields in a ``<ul 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 = "{0}/layout/buttongroup.html".format(TEMPLATE_PACK)

    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 = []
        for field in self.fields:
            field_list.append(
                render_field(field, form, form_style, context, template_pack=template_pack)
            )

        return render_to_string(self.template, Context({'buttongroup': self, 'field_list': field_list}))


class Button(crispy_forms_layout.BaseInput):
    """
    Used to create a Submit input descriptor for the {% crispy %} template tag:

    .. sourcecode:: python

        button = Button('Button 1', 'Press Me!')

    .. note:: The first argument is also slugified and turned into the id for the button.
    """
    input_type = 'button'
    field_classes = 'button'


class Submit(crispy_forms_layout.BaseInput):
    """
    Used to create a Submit button descriptor for the {% crispy %} template tag:

    .. sourcecode:: python

        submit = Submit('Search the Site', 'search this site')

    .. note:: The first argument is also slugified and turned into the id for the submit button.
    """
    input_type = 'submit'
    field_classes = 'submit button'


class Hidden(crispy_forms_layout.Hidden):
    """
    Used to create a Hidden input descriptor for the {% crispy %} template tag.
    """
    input_type = 'hidden'
    field_classes = 'hidden'


class Reset(crispy_forms_layout.BaseInput):
    """
    Used to create a Reset button input descriptor for the {% crispy %} template tag:

    .. sourcecode:: python

        reset = Reset('Reset This Form', 'Revert Me!')

    .. note:: The first argument is also slugified and turned into the id for the reset.
    """
    input_type = 'reset'
    field_classes = 'reset button'
{'fraction_non_alphanumeric': 0.11439490445859872, 'fraction_numerical': 0.0012738853503184713, 'mean_word_length': 3.236913113869401, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7046623', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2207, 'n_words': 691}