mirror of
https://github.com/Hopiu/django-fobi.git
synced 2026-05-28 05:43:59 +00:00
select_multiple pep8
This commit is contained in:
parent
6e8ada7f7e
commit
b52724927f
7 changed files with 97 additions and 65 deletions
|
|
@ -4,6 +4,7 @@ __copyright__ = '2014-2016 Artur Barseghyan'
|
|||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('default_app_config', 'UID',)
|
||||
|
||||
default_app_config = 'fobi.contrib.plugins.form_elements.fields.select_multiple.apps.Config'
|
||||
default_app_config = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple.apps.Config'
|
||||
|
||||
UID = 'select_multiple'
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ try:
|
|||
from django.apps import AppConfig
|
||||
|
||||
class Config(AppConfig):
|
||||
"""Config."""
|
||||
|
||||
name = 'fobi.contrib.plugins.form_elements.fields.select_multiple'
|
||||
label = 'fobi_contrib_plugins_form_elements_fields_select_multiple'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
from django.conf import settings
|
||||
|
||||
from . import defaults
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple.conf'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('get_setting',)
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from . import defaults
|
||||
|
||||
def get_setting(setting, override=None):
|
||||
"""
|
||||
"""Get setting.
|
||||
|
||||
Get a setting from
|
||||
`fobi.contrib.plugins.form_elements.fields.select_multiple` conf module,
|
||||
falling back to the default.
|
||||
|
|
@ -23,7 +25,11 @@ def get_setting(setting, override=None):
|
|||
"""
|
||||
if override is not None:
|
||||
return override
|
||||
if hasattr(settings, 'FOBI_FORM_ELEMENT_SELECT_MULTIPLE_{0}'.format(setting)):
|
||||
return getattr(settings, 'FOBI_FORM_ELEMENT_SELECT_MULTIPLE_{0}'.format(setting))
|
||||
if hasattr(settings,
|
||||
'FOBI_FORM_ELEMENT_SELECT_MULTIPLE_{0}'.format(setting)):
|
||||
return getattr(
|
||||
settings,
|
||||
'FOBI_FORM_ELEMENT_SELECT_MULTIPLE_{0}'.format(setting)
|
||||
)
|
||||
else:
|
||||
return getattr(defaults, setting)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple.defaults'
|
||||
from fobi.constants import SUBMIT_VALUE_AS_REPR
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple.defaults'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SUBMIT_VALUE_AS',)
|
||||
|
||||
from fobi.constants import SUBMIT_VALUE_AS_REPR
|
||||
|
||||
SUBMIT_VALUE_AS = SUBMIT_VALUE_AS_REPR
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple.fobi_form_elements'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectMultipleInputPlugin',)
|
||||
|
||||
from django.forms.fields import MultipleChoiceField
|
||||
from django.forms.widgets import SelectMultiple
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
|
@ -11,28 +5,33 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme
|
||||
from fobi.constants import (
|
||||
SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR
|
||||
)
|
||||
)
|
||||
from fobi.helpers import get_select_field_choices, safe_text
|
||||
|
||||
from . import UID
|
||||
from .forms import SelectMultipleInputForm
|
||||
from .settings import SUBMIT_VALUE_AS
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple.fobi_form_elements'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectMultipleInputPlugin',)
|
||||
|
||||
theme = get_theme(request=None, as_instance=True)
|
||||
|
||||
|
||||
class SelectMultipleInputPlugin(FormFieldPlugin):
|
||||
"""
|
||||
Select multiple field plugin.
|
||||
"""
|
||||
"""Select multiple field plugin."""
|
||||
|
||||
uid = UID
|
||||
name = _("Select multiple")
|
||||
group = _("Fields")
|
||||
form = SelectMultipleInputForm
|
||||
|
||||
def get_form_field_instances(self, request=None):
|
||||
"""
|
||||
Get form field instances.
|
||||
"""
|
||||
"""Get form field instances."""
|
||||
choices = get_select_field_choices(self.data.choices)
|
||||
|
||||
kwargs = {
|
||||
|
|
@ -41,7 +40,9 @@ class SelectMultipleInputPlugin(FormFieldPlugin):
|
|||
'initial': self.data.initial,
|
||||
'required': self.data.required,
|
||||
'choices': choices,
|
||||
'widget': SelectMultiple(attrs={'class': theme.form_element_html_class}),
|
||||
'widget': SelectMultiple(
|
||||
attrs={'class': theme.form_element_html_class}
|
||||
),
|
||||
}
|
||||
|
||||
return [(self.data.name, MultipleChoiceField, kwargs)]
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple.forms'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2015 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectMultipleInputForm',)
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from fobi.base import BaseFormFieldPluginForm, get_theme
|
||||
from fobi.helpers import validate_initial_for_multiple_choices
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple.forms'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectMultipleInputForm',)
|
||||
|
||||
theme = get_theme(request=None, as_instance=True)
|
||||
|
||||
|
||||
class SelectMultipleInputForm(forms.Form, BaseFormFieldPluginForm):
|
||||
"""
|
||||
Form for ``SelectMultipleInputPlugin``.
|
||||
"""
|
||||
"""Form for ``SelectMultipleInputPlugin``."""
|
||||
|
||||
plugin_data_fields = [
|
||||
("label", ""),
|
||||
("name", ""),
|
||||
|
|
@ -28,52 +28,72 @@ class SelectMultipleInputForm(forms.Form, BaseFormFieldPluginForm):
|
|||
label = forms.CharField(
|
||||
label=_("Label"),
|
||||
required=True,
|
||||
widget=forms.widgets.TextInput(attrs={'class': theme.form_element_html_class})
|
||||
widget=forms.widgets.TextInput(
|
||||
attrs={'class': theme.form_element_html_class}
|
||||
)
|
||||
)
|
||||
name = forms.CharField(
|
||||
label=_("Name"),
|
||||
required=True,
|
||||
widget=forms.widgets.TextInput(attrs={'class': theme.form_element_html_class})
|
||||
widget=forms.widgets.TextInput(
|
||||
attrs={'class': theme.form_element_html_class}
|
||||
)
|
||||
)
|
||||
choices = forms.CharField(
|
||||
label = _("Choices"),
|
||||
label=_("Choices"),
|
||||
required=False,
|
||||
help_text = _("Enter single values/pairs per line. Example:<code><br/>"
|
||||
" 1<br/>"
|
||||
" 2<br/>"
|
||||
" alpha, Alpha<br/>"
|
||||
" beta, Beta<br/>"
|
||||
" omega"
|
||||
"</code><br/>"
|
||||
"It finally transforms into the following HTML code:<code><br/>"
|
||||
' <select id="id_NAME_OF_THE_ELEMENT" name="NAME_OF_THE_ELEMENT"><br/>'
|
||||
' <option value="1">1</option><br/>'
|
||||
' <option value="2">2</option><br/>'
|
||||
' <option value="alpha">Alpha</option><br/>'
|
||||
' <option value="beta">Beta</option><br/>'
|
||||
' <option value="omega">omega</option><br/>'
|
||||
' </select>'
|
||||
"</code>"),
|
||||
widget=forms.widgets.Textarea(attrs={'class': theme.form_element_html_class})
|
||||
help_text=_("Enter single values/pairs per line. Example:<code><br/>"
|
||||
" 1<br/>"
|
||||
" 2<br/>"
|
||||
" alpha, Alpha<br/>"
|
||||
" beta, Beta<br/>"
|
||||
" omega"
|
||||
"</code><br/>"
|
||||
"It finally transforms into the following HTML "
|
||||
"code:<code><br/>"
|
||||
' '
|
||||
'<select id="id_NAME_OF_THE_ELEMENT" '
|
||||
'name="NAME_OF_THE_ELEMENT"><br/>'
|
||||
' '
|
||||
'<option value="1">1</option><br/>'
|
||||
' '
|
||||
'<option value="2">2</option><br/>'
|
||||
' '
|
||||
'<option value="alpha">Alpha</option><br/>'
|
||||
' '
|
||||
'<option value="beta">Beta</option><br/>'
|
||||
' '
|
||||
'<option value="omega">omega</option><br/>'
|
||||
' </select>'
|
||||
"</code>"),
|
||||
widget=forms.widgets.Textarea(
|
||||
attrs={'class': theme.form_element_html_class}
|
||||
)
|
||||
)
|
||||
help_text = forms.CharField(
|
||||
label=_("Help text"),
|
||||
required=False,
|
||||
widget=forms.widgets.Textarea(attrs={'class': theme.form_element_html_class})
|
||||
widget=forms.widgets.Textarea(
|
||||
attrs={'class': theme.form_element_html_class}
|
||||
)
|
||||
)
|
||||
initial = forms.CharField(
|
||||
label=_("Initial"),
|
||||
required=False,
|
||||
widget=forms.widgets.TextInput(attrs={'class': theme.form_element_html_class})
|
||||
widget=forms.widgets.TextInput(
|
||||
attrs={'class': theme.form_element_html_class}
|
||||
)
|
||||
)
|
||||
required = forms.BooleanField(
|
||||
label=_("Required"),
|
||||
required=False,
|
||||
widget=forms.widgets.CheckboxInput(attrs={'class': theme.form_element_checkbox_html_class})
|
||||
widget=forms.widgets.CheckboxInput(
|
||||
attrs={'class': theme.form_element_checkbox_html_class}
|
||||
)
|
||||
)
|
||||
|
||||
def clean_initial(self):
|
||||
"""
|
||||
Validating the initial value.
|
||||
"""
|
||||
return validate_initial_for_multiple_choices(self, 'choices', 'initial')
|
||||
"""Validating the initial value."""
|
||||
return validate_initial_for_multiple_choices(self,
|
||||
'choices',
|
||||
'initial')
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple.settings'
|
||||
from fobi.helpers import validate_submit_value_as
|
||||
|
||||
from .conf import get_setting
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple.settings'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SUBMIT_VALUE_AS',)
|
||||
|
||||
from fobi.helpers import validate_submit_value_as
|
||||
|
||||
from .conf import get_setting
|
||||
|
||||
SUBMIT_VALUE_AS = get_setting('SUBMIT_VALUE_AS')
|
||||
|
||||
validate_submit_value_as(SUBMIT_VALUE_AS)
|
||||
|
|
|
|||
Loading…
Reference in a new issue