mirror of
https://github.com/Hopiu/django-fobi.git
synced 2026-05-11 06:13:10 +00:00
select_model_object pep8
This commit is contained in:
parent
2717ddaf0c
commit
341f459c12
7 changed files with 88 additions and 62 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_model_object.apps.Config'
|
||||
default_app_config = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_model_object.apps.Config'
|
||||
|
||||
UID = 'select_model_object'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_model_object.apps'
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_model_object.apps'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
|
|
@ -8,6 +9,8 @@ try:
|
|||
from django.apps import AppConfig
|
||||
|
||||
class Config(AppConfig):
|
||||
"""Config."""
|
||||
|
||||
name = 'fobi.contrib.plugins.form_elements.fields.select_model_object'
|
||||
label = 'fobi_contrib_plugins_form_elements_fields_select_model_object'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_model_object.conf'
|
||||
from django.conf import settings
|
||||
|
||||
from . import defaults
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_model_object.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_model_object` conf
|
||||
module, falling back to the default.
|
||||
|
|
@ -23,7 +26,11 @@ def get_setting(setting, override=None):
|
|||
"""
|
||||
if override is not None:
|
||||
return override
|
||||
if hasattr(settings, 'FOBI_FORM_ELEMENT_SELECT_MODEL_OBJECT_{0}'.format(setting)):
|
||||
return getattr(settings, 'FOBI_FORM_ELEMENT_SELECT_MODEL_OBJECT_{0}'.format(setting))
|
||||
if hasattr(settings,
|
||||
'FOBI_FORM_ELEMENT_SELECT_MODEL_OBJECT_{0}'.format(setting)):
|
||||
return getattr(
|
||||
settings,
|
||||
'FOBI_FORM_ELEMENT_SELECT_MODEL_OBJECT_{0}'.format(setting)
|
||||
)
|
||||
else:
|
||||
return getattr(defaults, setting)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_model_object.defaults'
|
||||
from fobi.constants import SUBMIT_VALUE_AS_MIX
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_model_object.defaults'
|
||||
__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,47 +1,46 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_model_object.fobi_form_elements'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectModelObjectInputPlugin',)
|
||||
|
||||
from django.db import models
|
||||
from django.forms.models import ModelChoiceField
|
||||
from django.forms.widgets import Select
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from nine.versions import DJANGO_GTE_1_7
|
||||
|
||||
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 safe_text, get_app_label_and_model_name
|
||||
|
||||
from nine.versions import DJANGO_GTE_1_7
|
||||
|
||||
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 SelectModelObjectInputForm
|
||||
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
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_model_object.fobi_form_elements'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectModelObjectInputPlugin',)
|
||||
|
||||
theme = get_theme(request=None, as_instance=True)
|
||||
|
||||
|
||||
class SelectModelObjectInputPlugin(FormFieldPlugin):
|
||||
"""
|
||||
Select model object field plugin.
|
||||
"""
|
||||
"""Select model object field plugin."""
|
||||
|
||||
uid = UID
|
||||
name = _("Select model object")
|
||||
group = _("Fields")
|
||||
form = SelectModelObjectInputForm
|
||||
|
||||
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()
|
||||
|
|
@ -58,8 +57,7 @@ class SelectModelObjectInputPlugin(FormFieldPlugin):
|
|||
return [(self.data.name, ModelChoiceField, 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``.
|
||||
|
|
@ -91,7 +89,8 @@ class SelectModelObjectInputPlugin(FormFieldPlugin):
|
|||
safe_text(obj)
|
||||
)
|
||||
|
||||
# Overwrite ``cleaned_data`` of the ``form`` with object qualifier.
|
||||
# Overwrite ``cleaned_data`` of the ``form`` with object
|
||||
# qualifier.
|
||||
form.cleaned_data[self.data.name] = value
|
||||
|
||||
# It's critically important to return the ``form`` with updated
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_elements.fields.select_model_object.forms'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectModelObjectInputForm',)
|
||||
|
||||
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_model_object.forms'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('SelectModelObjectInputForm',)
|
||||
|
||||
theme = get_theme(request=None, as_instance=True)
|
||||
|
||||
|
||||
class SelectModelObjectInputForm(forms.Form, BaseFormFieldPluginForm):
|
||||
"""
|
||||
Form for ``SelectModelObjectPlugin``.
|
||||
"""
|
||||
"""Form for ``SelectModelObjectPlugin``."""
|
||||
|
||||
plugin_data_fields = [
|
||||
("label", ""),
|
||||
("name", ""),
|
||||
|
|
@ -30,40 +31,53 @@ class SelectModelObjectInputForm(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}
|
||||
)
|
||||
)
|
||||
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(SelectModelObjectInputForm, 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_model_object.settings'
|
||||
from fobi.helpers import validate_submit_value_as
|
||||
|
||||
from .conf import get_setting
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_elements.fields.' \
|
||||
'select_model_object.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