diff --git a/crispy_forms_foundation/__init__.py b/crispy_forms_foundation/__init__.py
index b767951..115e488 100644
--- a/crispy_forms_foundation/__init__.py
+++ b/crispy_forms_foundation/__init__.py
@@ -1,2 +1,2 @@
-"""Django application to add 'django-crispy-forms' layout objects for 'Foundation for sites'"""
+"""Django application to add 'django-crispy-forms' layout objects for 'Foundation for sites'""" # noqa: E501
__version__ = '0.5.4'
diff --git a/crispy_forms_foundation/forms.py b/crispy_forms_foundation/forms.py
index 7c6a218..f610cf0 100644
--- a/crispy_forms_foundation/forms.py
+++ b/crispy_forms_foundation/forms.py
@@ -10,29 +10,60 @@
from .layout import Submit, HTML, InlineSwitchField
+
class FoundationFormMixin(object):
"""
- Mixin to implement the layout helper that will automatically build a form layout
-
- Generally, you will prefer to use ``FoundationForm`` or ``FoundationModelForm`` instead.
-
- If you still want to directly use this mixin you'll just have to execute ``FoundationFormMixin.init_helper()`` in your form init.
- """
-
- title = None #: If set, defines the form's title
- layout = None #: If set, override the default layout for the form
- error_title = _("Errors :") #: Defines the error title for non field errors
- form_id = None #: Defines the id of the form
- classes = "foundation-form" #: Defines the classes used on the form
- action = "" #: Defines the action of the form. ``reverse`` will be called on the value. On failure the value will be assigned as is
- method = "post" #: Defines the method used for the action
- attrs = {} #: Defines the attributes of the form
- switches = True #: If True, will replace all fields checkboxes with switches
- submit = True #: Adds a submit button on the form. Can be set to a Submit object or a string which will be used as the value of the submit button
- title_templatestring = u"
" #: Template string used to display form title (if any)
+ Mixin to implement the layout helper that will automatically build a form
+ layout
+
+ Generally, you will prefer to use ``FoundationForm`` or
+ ``FoundationModelForm`` instead.
+
+ If you still want to directly use this mixin you'll just have to execute
+ ``FoundationFormMixin.init_helper()`` in your form init.
+
+ **Attributes**
+
+ title
+ If set, defines the form's title
+ layout
+ If set, override the default layout for the form
+ error_title
+ Defines the error title for non field errors
+ form_id
+ Defines the id of the form
+ classes
+ Defines the classes used on the form
+ action
+ Defines the action of the form. ``reverse`` will be called on the
+ value. On failure the value will be assigned as is
+ method
+ Defines the method used for the action
+ attrs
+ Defines the attributes of the form
+ switches
+ If True, will replace all fields checkboxes with switches
+ submit
+ Adds a submit button on the form. Can be set to a Submit object or
+ a string which will be used as the value of the submit button
+ title_templatestring
+ Template string used to display form title (if any)
+ """
+ title = None
+ layout = None
+ error_title = _("Errors :")
+ form_id = None
+ classes = "foundation-form"
+ action = ""
+ method = "post"
+ attrs = {}
+ switches = True
+ submit = True
+ title_templatestring = u""
def init_helper(self):
- # Put required HTML attribute on required fields so they are managed by Abide (if enabled)
+ # Put required HTML attribute on required fields so they are managed by
+ # Abide (if enabled)
if "data_abide" in self.attrs:
for field in self.fields.values():
if field.required:
@@ -46,19 +77,21 @@ def init_helper(self):
# Start from the given layout
self.helper = FormHelper()
self.helper.layout = deepcopy(self.layout)
-
- # Try to reverse form_action url, else fallback to use it as a simple string
+
+ # Try to reverse form_action url, else fallback to use it as a simple
+ # string
try:
self.helper.form_action = reverse(self.action)
except NoReverseMatch:
self.helper.form_action = self.action
if self.title:
- self.helper.layout.insert(0, HTML(self.title_templatestring.format(self.title)))
-
+ html = HTML(self.title_templatestring.format(self.title))
+ self.helper.layout.insert(0, html)
+
if self.form_id is not None:
self.helper.form_id = self.form_id
-
+
self.helper.form_class = self.classes
self.helper.form_method = self.method
self.helper.form_error_title = self.error_title
@@ -69,8 +102,11 @@ def init_helper(self):
layout_field_names = self.helper.layout.get_field_names()
# Transform checkbox fields to switches element
for pointer in layout_field_names:
- if isinstance(self.fields[pointer[1]].widget, forms.CheckboxInput):
- self.replace_layout_object(pointer[0], InlineSwitchField(pointer[1], switch_class="inline"))
+ if isinstance(self.fields[pointer[1]].widget,
+ forms.CheckboxInput):
+ field = InlineSwitchField(pointer[1],
+ switch_class="inline")
+ self.replace_layout_object(pointer[0], field)
if self.submit:
if isinstance(self.submit, Submit):
@@ -93,12 +129,14 @@ def replace_layout_object(self, position, instead):
else:
self.helper.layout.fields[position[0]] = instead
+
class FoundationForm(FoundationFormMixin, forms.Form):
"""
- A **Django form** that inherit from ``FoundationFormMixin`` to automatically build a form layout
+ A **Django form** that inherit from ``FoundationFormMixin`` to
+ automatically build a form layout
Example:
-
+
.. sourcecode:: python
from django import forms
@@ -110,7 +148,7 @@ class YourForm(FoundationForm):
layout = Layout(Fieldset("Section", "my_field", "my_field_2"))
switches = False
attrs = {'data_abide': ""}
-
+
title = forms.CharField(label='Title', required=True)
slug = forms.CharField(label='Slug', required=False)
@@ -122,10 +160,11 @@ def __init__(self, *args, **kwargs):
class FoundationModelForm(FoundationFormMixin, forms.ModelForm):
"""
- A **Django Model form** that inherit from ``FoundationFormMixin`` to automatically build a form layout
+ A **Django Model form** that inherit from ``FoundationFormMixin`` to
+ automatically build a form layout
Example:
-
+
.. sourcecode:: python
from crispy_forms_foundation.forms import FoundationModelForm
diff --git a/crispy_forms_foundation/layout/__init__.py b/crispy_forms_foundation/layout/__init__.py
index 52982fb..bbd09ee 100644
--- a/crispy_forms_foundation/layout/__init__.py
+++ b/crispy_forms_foundation/layout/__init__.py
@@ -1,9 +1,9 @@
"""
Layout items for Foundation components
-Inherits from the default **crispy_forms** layout objects to force templates on the
-right ``TEMPLATE_PACK`` (defined from ``settings.CRISPY_TEMPLATE_PACK``) and implements
-Foundation components.
+Inherits from the default **crispy_forms** layout objects to force templates on
+the right ``TEMPLATE_PACK`` (defined from ``settings.CRISPY_TEMPLATE_PACK``)
+and implements Foundation components.
"""
from __future__ import absolute_import
from django.conf import settings
@@ -21,4 +21,15 @@
VerticalTabHolder, AccordionItem,
AccordionHolder)
+
+__all__ = [
+ "Div", "Panel", "Layout", "UneditableField", "HTML", "Row", "RowFluid",
+ "Column", "MultiWidgetField", "Field", "MultiField", "SplitDateTimeField",
+ "InlineField", "InlineJustifiedField", "SwitchField", "InlineSwitchField",
+ "ButtonHolder", "ButtonHolderPanel", "ButtonGroup", "Button", "Submit",
+ "Hidden", "Reset", "Container", "ContainerHolder", "Fieldset", "TabItem",
+ "TabHolder", "VerticalTabHolder", "AccordionItem", "AccordionHolder",
+]
+
+
TEMPLATE_PACK = getattr(settings, 'CRISPY_TEMPLATE_PACK', 'foundation-5')
diff --git a/crispy_forms_foundation/layout/base.py b/crispy_forms_foundation/layout/base.py
index f16ce15..3bd4738 100644
--- a/crispy_forms_foundation/layout/base.py
+++ b/crispy_forms_foundation/layout/base.py
@@ -8,20 +8,30 @@
TEMPLATE_PACK = getattr(settings, 'CRISPY_TEMPLATE_PACK', 'foundation-5')
-class Layout(crispy_forms_layout.Layout): pass
-class UneditableField(crispy_forms_layout.HTML): pass
-class HTML(crispy_forms_layout.HTML): pass
+class Layout(crispy_forms_layout.Layout):
+ pass
+
+
+class UneditableField(crispy_forms_layout.HTML):
+ pass
+
+
+class HTML(crispy_forms_layout.HTML):
+ pass
class Div(crispy_forms_layout.Div):
"""
It wraps fields in a
- You can set ``css_id`` for a DOM id and ``css_class`` for a DOM class. Example:
+ You can set ``css_id`` for a DOM id and ``css_class`` for a DOM class.
+
+ Example:
.. sourcecode:: python
- Div('form_field_1', 'form_field_2', css_id='div-example', css_class='divs')
+ Div('form_field_1', 'form_field_2', css_id='div-example',
+ css_class='divs')
"""
template = "{0}/layout/div.html".format(TEMPLATE_PACK)
@@ -34,7 +44,8 @@ class Panel(crispy_forms_layout.Div):
.. sourcecode:: python
- Panel('form_field_1', 'form_field_2', css_id='div-example', css_class='divs')
+ Panel('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', '')+' panel'
diff --git a/crispy_forms_foundation/layout/buttons.py b/crispy_forms_foundation/layout/buttons.py
index 5471f38..42a565c 100644
--- a/crispy_forms_foundation/layout/buttons.py
+++ b/crispy_forms_foundation/layout/buttons.py
@@ -5,7 +5,7 @@
* `Foundation buttons
`_ for button components;
* `Foundation button groups `_ for button groups components;
-"""
+""" # noqa: E501
from django.conf import settings
from django.template import Context
from django.template.loader import render_to_string
@@ -13,14 +13,17 @@
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 ``