mirror of
https://github.com/Hopiu/django-fobi.git
synced 2026-05-11 06:13:10 +00:00
select_multiple_mptt_model_objects pep8
This commit is contained in:
parent
db77c51d14
commit
0887523aee
7 changed files with 103 additions and 64 deletions
|
|
@ -1,9 +1,11 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple_mptt_model_objects'
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple_mptt_model_objects'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__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_mptt_model_objects.apps.Config'
|
||||
default_app_config = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple_mptt_model_objects.apps.Config'
|
||||
|
||||
UID = 'select_multiple_mptt_model_objects'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple_mptt_model_objects.apps'
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple_mptt_model_objects.apps'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
|
|
@ -8,8 +9,12 @@ try:
|
|||
from django.apps import AppConfig
|
||||
|
||||
class Config(AppConfig):
|
||||
name = 'fobi.contrib.plugins.form_elements.fields.select_multiple_mptt_model_objects'
|
||||
label = 'fobi_contrib_plugins_form_elements_fields_select_multiple_mptt_model_objects'
|
||||
"""Config."""
|
||||
|
||||
name = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple_mptt_model_objects'
|
||||
label = 'fobi_contrib_plugins_form_elements_fields_' \
|
||||
'select_multiple_mptt_model_objects'
|
||||
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple_mptt_model_objects.conf'
|
||||
from django.conf import settings
|
||||
|
||||
from . import defaults
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple_mptt_model_objects.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 a setting from
|
||||
`fobi.contrib.plugins.form_elements.fields.select_multiple_mptt_model_objects`
|
||||
conf module, falling back to the default.
|
||||
`fobi.contrib.plugins.form_elements.fields.select_multiple_mptt_model_
|
||||
objects` conf module, falling back to the default.
|
||||
|
||||
If override is not None, it will be used instead of the setting.
|
||||
|
||||
|
|
@ -23,7 +25,17 @@ def get_setting(setting, override=None):
|
|||
"""
|
||||
if override is not None:
|
||||
return override
|
||||
if hasattr(settings, 'FOBI_FORM_ELEMENT_SELECT_MULTIPLE_MPTT_MODEL_OBJECTS_{0}'.format(setting)):
|
||||
return getattr(settings, 'FOBI_FORM_ELEMENT_SELECT_MULTIPLE_MPTT_MODEL_OBJECTS_{0}'.format(setting))
|
||||
if hasattr(
|
||||
settings,
|
||||
'FOBI_FORM_ELEMENT_SELECT_MULTIPLE_MPTT_MODEL_OBJECTS_{0}'.format(
|
||||
setting
|
||||
)
|
||||
):
|
||||
return getattr(
|
||||
settings,
|
||||
'FOBI_FORM_ELEMENT_SELECT_MULTIPLE_MPTT_MODEL_OBJECTS_{0}'.format(
|
||||
setting
|
||||
)
|
||||
)
|
||||
else:
|
||||
return getattr(defaults, setting)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple_mptt_model_objects.default'
|
||||
from fobi.constants import SUBMIT_VALUE_AS_MIX
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple_mptt_model_objects.default'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('IGNORED_MODELS', 'SUBMIT_VALUE_AS',)
|
||||
|
||||
from fobi.constants import SUBMIT_VALUE_AS_MIX
|
||||
|
||||
IGNORED_MODELS = []
|
||||
|
||||
SUBMIT_VALUE_AS = SUBMIT_VALUE_AS_MIX
|
||||
|
|
|
|||
|
|
@ -1,12 +1,5 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple_mptt_model_objects.fobi_form_elements'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectMultipleMPTTModelObjectsInputPlugin',)
|
||||
|
||||
import simplejson as json
|
||||
|
||||
from django.db import models
|
||||
from django.forms.widgets import SelectMultiple
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
|
@ -20,31 +13,36 @@ from fobi.helpers import safe_text, get_app_label_and_model_name
|
|||
|
||||
from nine.versions import DJANGO_GTE_1_7
|
||||
|
||||
from . import UID
|
||||
from .forms import SelectMultipleMPTTModelObjectsInputForm
|
||||
from .settings import SUBMIT_VALUE_AS
|
||||
|
||||
if DJANGO_GTE_1_7:
|
||||
from django.apps import apps
|
||||
get_model = apps.get_model
|
||||
else:
|
||||
from django.db.models import get_model
|
||||
|
||||
from . import UID
|
||||
from .forms import SelectMultipleMPTTModelObjectsInputForm
|
||||
from .settings import SUBMIT_VALUE_AS
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple_mptt_model_objects.fobi_form_elements'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectMultipleMPTTModelObjectsInputPlugin',)
|
||||
|
||||
theme = get_theme(request=None, as_instance=True)
|
||||
|
||||
|
||||
class SelectMultipleMPTTModelObjectsInputPlugin(FormFieldPlugin):
|
||||
"""
|
||||
Select multiple MPTT model object field plugin.
|
||||
"""
|
||||
"""Select multiple MPTT model object field plugin."""
|
||||
|
||||
uid = UID
|
||||
name = _("Select multiple MPTT model objects")
|
||||
group = _("Fields")
|
||||
form = SelectMultipleMPTTModelObjectsInputForm
|
||||
|
||||
def get_form_field_instances(self, request=None):
|
||||
"""
|
||||
Get form field instances.
|
||||
"""
|
||||
"""Get form field instances."""
|
||||
app_label, model_name = get_app_label_and_model_name(self.data.model)
|
||||
model = get_model(app_label, model_name)
|
||||
queryset = model._default_manager.all()
|
||||
|
|
@ -55,16 +53,18 @@ class SelectMultipleMPTTModelObjectsInputPlugin(FormFieldPlugin):
|
|||
'initial': self.data.initial,
|
||||
'required': self.data.required,
|
||||
'queryset': queryset,
|
||||
'widget': SelectMultiple(attrs={'class': theme.form_element_html_class}),
|
||||
'widget': SelectMultiple(
|
||||
attrs={'class': theme.form_element_html_class}
|
||||
),
|
||||
}
|
||||
|
||||
return [(self.data.name, TreeNodeMultipleChoiceField, kwargs)]
|
||||
|
||||
def submit_plugin_form_data(self, form_entry, request, form):
|
||||
"""
|
||||
Submit plugin form data/process.
|
||||
"""Submit plugin form data/process.
|
||||
|
||||
:param fobi.models.FormEntry form_entry: Instance of ``fobi.models.FormEntry``.
|
||||
:param fobi.models.FormEntry form_entry: Instance of
|
||||
``fobi.models.FormEntry``.
|
||||
:param django.http.HttpRequest request:
|
||||
:param django.forms.Form form:
|
||||
"""
|
||||
|
|
@ -106,4 +106,6 @@ class SelectMultipleMPTTModelObjectsInputPlugin(FormFieldPlugin):
|
|||
return form
|
||||
|
||||
|
||||
form_element_plugin_registry.register(SelectMultipleMPTTModelObjectsInputPlugin)
|
||||
form_element_plugin_registry.register(
|
||||
SelectMultipleMPTTModelObjectsInputPlugin
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple_mptt_model_objects.forms'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectMultipleMPTTModelObjectsInputForm',)
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
|
@ -12,12 +6,19 @@ from fobi.helpers import get_registered_models
|
|||
|
||||
from .settings import IGNORED_MODELS
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple_mptt_model_objects.forms'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectMultipleMPTTModelObjectsInputForm',)
|
||||
|
||||
theme = get_theme(request=None, as_instance=True)
|
||||
|
||||
class SelectMultipleMPTTModelObjectsInputForm(forms.Form, BaseFormFieldPluginForm):
|
||||
"""
|
||||
Form for ``SelectMultipleMPTTModelObjectsPlugin``.
|
||||
"""
|
||||
class SelectMultipleMPTTModelObjectsInputForm(forms.Form,
|
||||
BaseFormFieldPluginForm):
|
||||
"""Form for ``SelectMultipleMPTTModelObjectsPlugin``."""
|
||||
|
||||
plugin_data_fields = [
|
||||
("label", ""),
|
||||
("name", ""),
|
||||
|
|
@ -30,40 +31,55 @@ class SelectMultipleMPTTModelObjectsInputForm(forms.Form, BaseFormFieldPluginFor
|
|||
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}
|
||||
)
|
||||
)
|
||||
model = forms.ChoiceField(
|
||||
label = _("Model"),
|
||||
choices = [],
|
||||
label=_("Model"),
|
||||
choices=[],
|
||||
required=False,
|
||||
widget = forms.widgets.Select(attrs={'class': theme.form_element_html_class})
|
||||
widget=forms.widgets.Select(
|
||||
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 __init__(self, *args, **kwargs):
|
||||
"""
|
||||
"""Constructor.
|
||||
|
||||
In order to avoid static calls to `get_registered_models`.
|
||||
"""
|
||||
super(SelectMultipleMPTTModelObjectsInputForm, self).__init__(*args, **kwargs)
|
||||
super(SelectMultipleMPTTModelObjectsInputForm, self).__init__(
|
||||
*args, **kwargs
|
||||
)
|
||||
self.fields['model'].choices = get_registered_models(
|
||||
ignore = IGNORED_MODELS
|
||||
)
|
||||
ignore=IGNORED_MODELS
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple_mptt_model_objects.settings'
|
||||
from fobi.helpers import validate_submit_value_as
|
||||
|
||||
from .conf import get_setting
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_multiple_mptt_model_objects.settings'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('IGNORED_MODELS', 'SUBMIT_VALUE_AS',)
|
||||
|
||||
from fobi.helpers import validate_submit_value_as
|
||||
|
||||
from .conf import get_setting
|
||||
|
||||
IGNORED_MODELS = get_setting('IGNORED_MODELS')
|
||||
|
||||
SUBMIT_VALUE_AS = get_setting('SUBMIT_VALUE_AS')
|
||||
|
|
|
|||
Loading…
Reference in a new issue