mirror of
https://github.com/Hopiu/django-fobi.git
synced 2026-05-10 13:54:41 +00:00
prepare 0.4.28; fix improperly picked configuration of select_multiple_model_objects plugin; allowed long identifiers of models; fix admin bulk change of the plugins; control of the submitted value for select_model_object and select_multiple_model_objects; docs updated
This commit is contained in:
parent
123ca3c4fc
commit
888646c3c8
24 changed files with 330 additions and 54 deletions
|
|
@ -17,8 +17,17 @@ are used for versioning (schema follows below):
|
|||
|
||||
0.4.28
|
||||
-------------------------------------
|
||||
yyyy-mm-dd (not yet released)
|
||||
2015-03-13
|
||||
|
||||
- Fix improperly picked configurations of the
|
||||
`fobi.contrib.plugins.form_elements.fields.select_multiple_model_objects`
|
||||
plugin.
|
||||
- Long identifiers of models can now be safely used in foreign key plugins
|
||||
(such as
|
||||
`fobi.contrib.plugins.form_elements.fields.select_model_object_plugin` and
|
||||
`fobi.contrib.plugins.form_elements.fields.select_multiple_model_objects`
|
||||
plugins).
|
||||
- Fixed admin bulk change of the plugins.
|
||||
- From now it's possible to have some control/configure the following plugins
|
||||
for the submitted value:
|
||||
|
||||
|
|
@ -37,10 +46,10 @@ yyyy-mm-dd (not yet released)
|
|||
-------------------------------------
|
||||
2015-03-12
|
||||
|
||||
- Temporary allow the `db_store` plugin to be used multiple times per form,
|
||||
until the bug with not being able to assign the `db_store` plugin to the form
|
||||
due to incorrect handling of restrictions (`allow_multiple`) introduced in
|
||||
previous version is properly fixed.
|
||||
- Temporary allow the `fobi.contrib.plugins.form_handlers.db_store` plugin to
|
||||
be used multiple times per form, until the bug with not being able to assign
|
||||
the `db_store` plugin to the form due to incorrect handling of restrictions
|
||||
(``allow_multiple``) introduced in previous version is properly fixed.
|
||||
- From now it's possible to have some control/configure the following plugins
|
||||
for the submitted value:
|
||||
|
||||
|
|
@ -61,7 +70,9 @@ yyyy-mm-dd (not yet released)
|
|||
-------------------------------------
|
||||
2015-03-06
|
||||
|
||||
- Validate `email`, `integer` and `url` plugins initial values.
|
||||
- Validate `fobi.contrib.plugins.form_elements.fields.email`,
|
||||
`fobi.contrib.plugins.form_elements.fields.integer` and
|
||||
`fobi.contrib.plugins.form_elements.fields.url` plugins initial values.
|
||||
- Properly show field types "checkbox" and "radio" in the `input` plugin (as
|
||||
previously they showed up too large).
|
||||
- It's now possible to restrict multiple usage of form handler plugins via
|
||||
|
|
|
|||
31
README.rst
31
README.rst
|
|
@ -1387,6 +1387,37 @@ should be constructing your URL to the form as follows:
|
|||
|
||||
http://127.0.0.1:8001/fobi/view/test-form/?fobi_initial_data&email=test@example.com&age=19
|
||||
|
||||
Submitted form element plugins values
|
||||
===============================================
|
||||
While some values of form element plugins are submitted as is, some others
|
||||
need additional processing. There are 3 behaviours taken into consideration:
|
||||
|
||||
- "val": value is being sent as is.
|
||||
- "repr": (human readable) representatio of the value is used.
|
||||
- "mix": mix of value as is and human readable representation.
|
||||
|
||||
The following plugins have been made configurable in such a way, that
|
||||
developers can choose the desired behaviour in projects' settings:
|
||||
|
||||
- ``FOBI_FORM_ELEMENT_RADIO_SUBMIT_VALUE_AS``
|
||||
- ``FOBI_FORM_ELEMENT_SELECT_SUBMIT_VALUE_AS``
|
||||
- ``FOBI_FORM_ELEMENT_SELECT_MULTIPLE_SUBMIT_VALUE_AS``
|
||||
- ``FOBI_FORM_ELEMENT_SELECT_MODEL_OBJECT_SUBMIT_VALUE_AS``
|
||||
- ``FOBI_FORM_ELEMENT_SELECT_MULTIPLE_MODEL_OBJECTS_SUBMIT_VALUE_AS``
|
||||
|
||||
See the README.rst in each of the following plugins for more information.
|
||||
|
||||
- `Radio select (radio button)
|
||||
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/radio/>`__
|
||||
- `Select (drop-down)
|
||||
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select/>`__
|
||||
- `Select model object (drop-down)
|
||||
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_model_object/>`__
|
||||
- `Select multiple (drop-down)
|
||||
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_multiple/>`__
|
||||
- `Select multiple model objects (drop-down)
|
||||
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/>`__
|
||||
|
||||
Available translations
|
||||
===============================================
|
||||
English is the primary language.
|
||||
|
|
|
|||
14
TODOS.rst
14
TODOS.rst
|
|
@ -263,13 +263,7 @@ Should haves
|
|||
Think of fixing that by allowing to exclude certain fields from being
|
||||
processed by form handlers.
|
||||
+ Add a property "allow_multiple" to the form handlers, for form handlers.
|
||||
- Fix the issue with `db_store` plugin and `allow_multiple` property (if
|
||||
set to True tests fail).
|
||||
- Fix the issue with `initial` for `select_multiple` plugin. At the moment,
|
||||
setting initial doesn't seem to work.
|
||||
- Document the `SUBMIT_VALUE_AS` in main documentation and mention in the
|
||||
readme of all appropriate plugins.
|
||||
- Make it possible for developers to decide (in settings) what kind of
|
||||
+ Make it possible for developers to decide (in settings) what kind of
|
||||
values do they want to have saved. By default, return the label for
|
||||
select-like fields (`radio`, `select`, `select_multiple`), the str/unicode
|
||||
for foreign keys (`select_model_object`, `select_multiple_model_objects`).
|
||||
|
|
@ -280,6 +274,12 @@ Should haves
|
|||
submitted. Mix is a mix of the "val" and "repr" as "repr (val)". For foreign
|
||||
keys, it would be as follows: app.module.pk.value (mix), app.module.pk (val),
|
||||
value (repr).
|
||||
+ Document the `SUBMIT_VALUE_AS` in main documentation and mention in the
|
||||
readme of all appropriate plugins.
|
||||
- Fix the issue with `db_store` plugin and `allow_multiple` property (if
|
||||
set to True tests fail).
|
||||
- Fix the issue with `initial` for `select_multiple` plugin. At the moment,
|
||||
setting initial doesn't seem to work.
|
||||
- Document the changes.
|
||||
- Find out why subclassing the ``select_model_object`` plugin didn't work.
|
||||
- Rename the ``simple`` theme into ``django_admin_style_theme``.
|
||||
|
|
|
|||
|
|
@ -1387,6 +1387,37 @@ should be constructing your URL to the form as follows:
|
|||
|
||||
http://127.0.0.1:8001/fobi/view/test-form/?fobi_initial_data&email=test@example.com&age=19
|
||||
|
||||
Submitted form element plugins values
|
||||
===============================================
|
||||
While some values of form element plugins are submitted as is, some others
|
||||
need additional processing. There are 3 behaviours taken into consideration:
|
||||
|
||||
- "val": value is being sent as is.
|
||||
- "repr": (human readable) representatio of the value is used.
|
||||
- "mix": mix of value as is and human readable representation.
|
||||
|
||||
The following plugins have been made configurable in such a way, that
|
||||
developers can choose the desired behaviour in projects' settings:
|
||||
|
||||
- ``FOBI_FORM_ELEMENT_RADIO_SUBMIT_VALUE_AS``
|
||||
- ``FOBI_FORM_ELEMENT_SELECT_SUBMIT_VALUE_AS``
|
||||
- ``FOBI_FORM_ELEMENT_SELECT_MULTIPLE_SUBMIT_VALUE_AS``
|
||||
- ``FOBI_FORM_ELEMENT_SELECT_MODEL_OBJECT_SUBMIT_VALUE_AS``
|
||||
- ``FOBI_FORM_ELEMENT_SELECT_MULTIPLE_MODEL_OBJECTS_SUBMIT_VALUE_AS``
|
||||
|
||||
See the README.rst in each of the following plugins for more information.
|
||||
|
||||
- `Radio select (radio button)
|
||||
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/radio/>`__
|
||||
- `Select (drop-down)
|
||||
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select/>`__
|
||||
- `Select model object (drop-down)
|
||||
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_model_object/>`__
|
||||
- `Select multiple (drop-down)
|
||||
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_multiple/>`__
|
||||
- `Select multiple model objects (drop-down)
|
||||
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/>`__
|
||||
|
||||
Available translations
|
||||
===============================================
|
||||
English is the primary language.
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -63,7 +63,7 @@ for static_dir in static_dirs:
|
|||
for locale_dir in locale_dirs:
|
||||
locale_files += [os.path.join(locale_dir, f) for f in os.listdir(locale_dir)]
|
||||
|
||||
version = '0.4.27'
|
||||
version = '0.4.28'
|
||||
|
||||
install_requires = [
|
||||
'Pillow>=2.0.0',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
__title__ = 'django-fobi'
|
||||
__version__ = '0.4.27'
|
||||
__build__ = 0x000030
|
||||
__version__ = '0.4.28'
|
||||
__build__ = 0x000031
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2015 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ __license__ = 'GPL 2.0/LGPL 2.1'
|
|||
from django.contrib import admin
|
||||
from django.contrib.admin import helpers
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.html import strip_tags
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.conf.urls import patterns, url
|
||||
|
|
@ -300,6 +301,7 @@ class BasePluginModelAdmin(admin.ModelAdmin):
|
|||
data = request.POST,
|
||||
files = request.FILES
|
||||
)
|
||||
|
||||
if form.is_valid():
|
||||
ids = form.cleaned_data.pop('selected_plugins').split(',')
|
||||
users = form.cleaned_data.pop('users')
|
||||
|
|
@ -336,6 +338,12 @@ class BasePluginModelAdmin(admin.ModelAdmin):
|
|||
_('{0} plugins were changed successfully.').format(len(ids))
|
||||
)
|
||||
return redirect(changelist_named_url)
|
||||
else:
|
||||
messages.warning(
|
||||
request,
|
||||
_('Form contains errors: {}').format(strip_tags(form.errors))
|
||||
)
|
||||
return redirect(changelist_named_url)
|
||||
else:
|
||||
messages.warning(
|
||||
request,
|
||||
|
|
|
|||
|
|
@ -25,3 +25,54 @@ Installation
|
|||
|
||||
3. Assign appropriate permissions to the target users/groups to be using
|
||||
the plugin if ``FOBI_RESTRICT_PLUGIN_ACCESS`` is set to True.
|
||||
|
||||
4. By default, the submitted form value of `radio`
|
||||
elements is label (human readable representation of the value chosen).
|
||||
However, that part of the bahaviour has been made configurable. You can
|
||||
choose between the following options:
|
||||
|
||||
Consider the following list of (value, label) choices (the first element in
|
||||
the tuple is value, the second element is label):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
[
|
||||
('alpha', 'Alpha'),
|
||||
('beta', 'Beta'),
|
||||
('gamma', 'Gamma'),
|
||||
]
|
||||
|
||||
- "val": `value` (example: "alpha").
|
||||
- "repr" (default): `label` (example: "Alpha").
|
||||
- "mix": `value (label)` (examle: "Alpha (alpha)").
|
||||
|
||||
Simply set the
|
||||
``FOBI_FORM_ELEMENT_RADIO_SUBMIT_VALUE_AS`` assign one of the following
|
||||
values: "val", "repr" or "mix" to get the desired behaviour.
|
||||
|
||||
Usage
|
||||
===============================================
|
||||
You should be entering a single choice per line. Choice might
|
||||
consist of just a single value or value/label pair.
|
||||
|
||||
For example:
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
1
|
||||
2
|
||||
alpha, Alpha
|
||||
beta, Beta
|
||||
omega
|
||||
|
||||
The following HTML would be made of:
|
||||
|
||||
.. code-block:: html
|
||||
|
||||
<select id="id_NAME_OF_THE_ELEMENT" name="NAME_OF_THE_ELEMENT">
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="alpha">Alpha</option>
|
||||
<option value="beta">Beta</option>
|
||||
<option value="omega">omega</option>
|
||||
</select>
|
||||
|
|
|
|||
|
|
@ -69,14 +69,14 @@ class RadioInputPlugin(FormFieldPlugin):
|
|||
if value in choices:
|
||||
# Handle the submitted form value
|
||||
|
||||
repr = safe_text(choices.get(value))
|
||||
label = safe_text(choices.get(value))
|
||||
|
||||
# Should be returned as repr
|
||||
if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR:
|
||||
value = repr
|
||||
value = label
|
||||
# Should be returned as mix
|
||||
else:
|
||||
value = "{0} ({1})".format(repr, value)
|
||||
value = "{0} ({1})".format(label, value)
|
||||
|
||||
# Overwrite ``cleaned_data`` of the ``form`` with object
|
||||
# qualifier.
|
||||
|
|
|
|||
|
|
@ -26,6 +26,30 @@ Installation
|
|||
3. Assign appropriate permissions to the target users/groups to be using
|
||||
the plugin if ``FOBI_RESTRICT_PLUGIN_ACCESS`` is set to True.
|
||||
|
||||
4. By default, the submitted form value of `select`
|
||||
elements is label (human readable representation of the value chosen).
|
||||
However, that part of the bahaviour has been made configurable. You can
|
||||
choose between the following options:
|
||||
|
||||
Consider the following list of (value, label) choices (the first element in
|
||||
the tuple is value, the second element is label):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
[
|
||||
('alpha', 'Alpha'),
|
||||
('beta', 'Beta'),
|
||||
('gamma', 'Gamma'),
|
||||
]
|
||||
|
||||
- "val": `value` (example: "alpha").
|
||||
- "repr" (default): `label` (example: "Alpha").
|
||||
- "mix": `value (label)` (examle: "Alpha (alpha)").
|
||||
|
||||
Simply set the
|
||||
``FOBI_FORM_ELEMENT_SELECT_SUBMIT_VALUE_AS`` assign one of the following
|
||||
values: "val", "repr" or "mix" to get the desired behaviour.
|
||||
|
||||
Usage
|
||||
===============================================
|
||||
You should be entering a single choice per line. Choice might
|
||||
|
|
|
|||
|
|
@ -70,14 +70,14 @@ class SelectInputPlugin(FormFieldPlugin):
|
|||
if value in choices:
|
||||
# Handle the submitted form value
|
||||
|
||||
repr = safe_text(choices.get(value))
|
||||
label = safe_text(choices.get(value))
|
||||
|
||||
# Should be returned as repr
|
||||
if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR:
|
||||
value = repr
|
||||
value = label
|
||||
# Should be returned as mix
|
||||
else:
|
||||
value = "{0} ({1})".format(repr, value)
|
||||
value = "{0} ({1})".format(label, value)
|
||||
|
||||
# Overwrite ``cleaned_data`` of the ``form`` with object
|
||||
# qualifier.
|
||||
|
|
|
|||
|
|
@ -36,3 +36,16 @@ Installation
|
|||
'auth.User',
|
||||
'auth.Group',
|
||||
]
|
||||
|
||||
5. By default, the submitted form value of `select_model_object` elements is
|
||||
`app_label.model_name.object_pk.object_repr`. However, that part of the
|
||||
bahaviour has been made configurable. You can choose between the following
|
||||
options:
|
||||
|
||||
- "val": `app_label.model_name.object_pk.object_repr`.
|
||||
- "repr": `object_repr` (uses the ``__unicode__`` nethod of the model).
|
||||
- "mix" (default): `app_label.model_name.object_pk.object_repr`.
|
||||
|
||||
Simply set the ``FOBI_FORM_ELEMENT_SELECT_MODEL_OBJECT_SUBMIT_VALUE_AS``
|
||||
assign one of the following values: "val", "repr" or "mix" to get the
|
||||
desired behaviour.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ __title__ = 'fobi.contrib.plugins.form_elements.fields.select_model_object.defau
|
|||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = 'Copyright (c) 2014 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('IGNORED_MODELS',)
|
||||
__all__ = ('IGNORED_MODELS', 'SUBMIT_VALUE_AS',)
|
||||
|
||||
from fobi.constants import SUBMIT_VALUE_AS_MIX
|
||||
|
||||
IGNORED_MODELS = []
|
||||
|
||||
SUBMIT_VALUE_AS = SUBMIT_VALUE_AS_MIX
|
||||
|
|
|
|||
|
|
@ -10,10 +10,15 @@ from django.forms.widgets import Select
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme
|
||||
from fobi.helpers import safe_text
|
||||
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 fobi.contrib.plugins.form_elements.fields.select_model_object import UID
|
||||
from fobi.contrib.plugins.form_elements.fields.select_model_object.forms \
|
||||
import SelectModelObjectInputForm
|
||||
from fobi.contrib.plugins.form_elements.fields.select_model_object.settings \
|
||||
import SUBMIT_VALUE_AS
|
||||
|
||||
theme = get_theme(request=None, as_instance=True)
|
||||
|
||||
|
|
@ -30,7 +35,7 @@ class SelectModelObjectInputPlugin(FormFieldPlugin):
|
|||
"""
|
||||
Get form field instances.
|
||||
"""
|
||||
app_label, model_name = self.data.model.split('.')
|
||||
app_label, model_name = get_app_label_and_model_name(self.data.model)
|
||||
model = models.get_model(app_label, model_name)
|
||||
queryset = model._default_manager.all()
|
||||
|
||||
|
|
@ -54,16 +59,30 @@ class SelectModelObjectInputPlugin(FormFieldPlugin):
|
|||
:param django.http.HttpRequest request:
|
||||
:param django.forms.Form form:
|
||||
"""
|
||||
# In case if we should submit value as is, we don't return anything.
|
||||
# In other cases, we proceed further.
|
||||
|
||||
# Get the object
|
||||
obj = form.cleaned_data.get(self.data.name, None)
|
||||
if obj:
|
||||
# Handle the submitted form value
|
||||
value = '{0}.{1}.{2}.{3}'.format(
|
||||
obj._meta.app_label,
|
||||
obj._meta.module_name,
|
||||
obj.pk,
|
||||
safe_text(obj)
|
||||
)
|
||||
value = None
|
||||
# Should be returned as repr
|
||||
if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR:
|
||||
value = safe_text(obj)
|
||||
elif SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_VAL:
|
||||
value = '{0}.{1}.{2}'.format(
|
||||
obj._meta.app_label,
|
||||
obj._meta.module_name,
|
||||
obj.pk
|
||||
)
|
||||
else:
|
||||
# Handle the submitted form value
|
||||
value = '{0}.{1}.{2}.{3}'.format(
|
||||
obj._meta.app_label,
|
||||
obj._meta.module_name,
|
||||
obj.pk,
|
||||
safe_text(obj)
|
||||
)
|
||||
|
||||
# Overwrite ``cleaned_data`` of the ``form`` with object qualifier.
|
||||
form.cleaned_data[self.data.name] = value
|
||||
|
|
|
|||
|
|
@ -2,9 +2,15 @@ __title__ = 'fobi.contrib.plugins.form_elements.fields.select_model_object.setti
|
|||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = 'Copyright (c) 2014 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('IGNORED_MODELS',)
|
||||
__all__ = ('IGNORED_MODELS', 'SUBMIT_VALUE_AS',)
|
||||
|
||||
from fobi.contrib.plugins.form_elements.fields.select_model_object.conf \
|
||||
import get_setting
|
||||
from fobi.helpers import validate_submit_value_as
|
||||
from fobi.contrib.plugins.form_elements.fields.select_model_object.conf import (
|
||||
get_setting
|
||||
)
|
||||
|
||||
IGNORED_MODELS = get_setting('IGNORED_MODELS')
|
||||
|
||||
SUBMIT_VALUE_AS = get_setting('SUBMIT_VALUE_AS')
|
||||
|
||||
validate_submit_value_as(SUBMIT_VALUE_AS)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,30 @@ Installation
|
|||
3. Assign appropriate permissions to the target users/groups to be using
|
||||
the plugin if ``FOBI_RESTRICT_PLUGIN_ACCESS`` is set to True.
|
||||
|
||||
4. By default, the submitted form value of `select_multiple`
|
||||
elements is label (human readable representation of the value chosen).
|
||||
However, that part of the bahaviour has been made configurable. You can
|
||||
choose between the following options:
|
||||
|
||||
Consider the following list of (value, label) choices (the first element in
|
||||
the tuple is value, the second element is label):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
[
|
||||
('alpha', 'Alpha'),
|
||||
('beta', 'Beta'),
|
||||
('gamma', 'Gamma'),
|
||||
]
|
||||
|
||||
- "val": `value` (example: "alpha").
|
||||
- "repr" (default): `label` (example: "Alpha").
|
||||
- "mix": `value (label)` (examle: "Alpha (alpha)").
|
||||
|
||||
Simply set the
|
||||
``FOBI_FORM_ELEMENT_SELECT_MULTIPLE_SUBMIT_VALUE_AS`` assign one of the
|
||||
following values: "val", "repr" or "mix" to get the desired behaviour.
|
||||
|
||||
Usage
|
||||
===============================================
|
||||
You should be entering a single choice per line. Choice might
|
||||
|
|
|
|||
|
|
@ -74,14 +74,14 @@ class SelectMultipleInputPlugin(FormFieldPlugin):
|
|||
# Handle the submitted form value
|
||||
|
||||
if value in choices:
|
||||
repr = safe_text(choices.get(value))
|
||||
label = safe_text(choices.get(value))
|
||||
|
||||
# Should be returned as repr
|
||||
if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR:
|
||||
value = repr
|
||||
value = label
|
||||
# Should be returned as mix
|
||||
else:
|
||||
value = "{0} ({1})".format(repr, value)
|
||||
value = "{0} ({1})".format(label, value)
|
||||
|
||||
ret_values.append(value)
|
||||
|
||||
|
|
|
|||
|
|
@ -38,3 +38,17 @@ Installation
|
|||
'auth.User',
|
||||
'auth.Group',
|
||||
]
|
||||
|
||||
5. By default, the submitted form value of `select_multiple_model_objects`
|
||||
elements is `app_label.model_name.object_pk.object_repr`. However, that part
|
||||
of the bahaviour has been made configurable. You can choose between the
|
||||
following options:
|
||||
|
||||
- "val": `app_label.model_name.object_pk.object_repr`.
|
||||
- "repr": `object_repr` (uses the ``__unicode__`` nethod of the model).
|
||||
- "mix" (default): `app_label.model_name.object_pk.object_repr`.
|
||||
|
||||
Simply set the
|
||||
``FOBI_FORM_ELEMENT_SELECT_MULTIPLE_MODEL_OBJECTS_SUBMIT_VALUE_AS`` assign
|
||||
one of the following values: "val", "repr" or "mix" to get the desired
|
||||
behaviour.
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ __all__ = ('get_setting',)
|
|||
|
||||
from django.conf import settings
|
||||
|
||||
from fobi.contrib.plugins.form_elements.fields.select_model_object import defaults
|
||||
from fobi.contrib.plugins.form_elements.fields.select_multiple_model_objects \
|
||||
import defaults
|
||||
|
||||
def get_setting(setting, override=None):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ __title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple_model_obj
|
|||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = 'Copyright (c) 2014-2015 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('IGNORED_MODELS',)
|
||||
__all__ = ('IGNORED_MODELS', 'SUBMIT_VALUE_AS',)
|
||||
|
||||
from fobi.constants import SUBMIT_VALUE_AS_MIX
|
||||
|
||||
IGNORED_MODELS = []
|
||||
|
||||
SUBMIT_VALUE_AS = SUBMIT_VALUE_AS_MIX
|
||||
|
|
|
|||
|
|
@ -12,12 +12,17 @@ from django.forms.widgets import SelectMultiple
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme
|
||||
from fobi.helpers import safe_text #, admin_change_url
|
||||
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 fobi.contrib.plugins.form_elements.fields.select_multiple_model_objects \
|
||||
import UID
|
||||
from fobi.contrib.plugins.form_elements.fields.select_multiple_model_objects.forms import (
|
||||
SelectMultipleModelObjectsInputForm
|
||||
)
|
||||
from fobi.contrib.plugins.form_elements.fields.select_multiple_model_objects.settings \
|
||||
import SUBMIT_VALUE_AS
|
||||
|
||||
theme = get_theme(request=None, as_instance=True)
|
||||
|
||||
|
|
@ -34,7 +39,7 @@ class SelectMultipleModelObjectsInputPlugin(FormFieldPlugin):
|
|||
"""
|
||||
Get form field instances.
|
||||
"""
|
||||
app_label, model_name = self.data.model.split('.')
|
||||
app_label, model_name = get_app_label_and_model_name(self.data.model)
|
||||
model = models.get_model(app_label, model_name)
|
||||
queryset = model._default_manager.all()
|
||||
|
||||
|
|
@ -57,20 +62,34 @@ class SelectMultipleModelObjectsInputPlugin(FormFieldPlugin):
|
|||
:param django.http.HttpRequest request:
|
||||
:param django.forms.Form form:
|
||||
"""
|
||||
# In case if we should submit value as is, we don't return anything.
|
||||
# In other cases, we proceed further.
|
||||
|
||||
# Get the object
|
||||
objs = form.cleaned_data.get(self.data.name, [])
|
||||
|
||||
values = []
|
||||
|
||||
for obj in objs:
|
||||
if objs:
|
||||
# Handle the submitted form value
|
||||
value = '{0}.{1}.{2}.{3}'.format(
|
||||
obj._meta.app_label,
|
||||
obj._meta.module_name,
|
||||
obj.pk,
|
||||
safe_text(obj)
|
||||
)
|
||||
if obj:
|
||||
value = None
|
||||
# Should be returned as repr
|
||||
if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR:
|
||||
value = safe_text(obj)
|
||||
elif SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_VAL:
|
||||
value = '{0}.{1}.{2}'.format(
|
||||
obj._meta.app_label,
|
||||
obj._meta.module_name,
|
||||
obj.pk
|
||||
)
|
||||
else:
|
||||
# Handle the submitted form value
|
||||
value = '{0}.{1}.{2}.{3}'.format(
|
||||
obj._meta.app_label,
|
||||
obj._meta.module_name,
|
||||
obj.pk,
|
||||
safe_text(obj)
|
||||
)
|
||||
values.append(value)
|
||||
|
||||
# Overwrite ``cleaned_data`` of the ``form`` with object qualifier.
|
||||
|
|
|
|||
|
|
@ -2,9 +2,14 @@ __title__ = 'fobi.contrib.plugins.form_elements.fields.select_multiple_model_obj
|
|||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = 'Copyright (c) 2014-2015 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('IGNORED_MODELS',)
|
||||
__all__ = ('IGNORED_MODELS', 'SUBMIT_VALUE_AS',)
|
||||
|
||||
from fobi.helpers import validate_submit_value_as
|
||||
from fobi.contrib.plugins.form_elements.fields.select_multiple_model_objects.conf \
|
||||
import get_setting
|
||||
|
||||
IGNORED_MODELS = get_setting('IGNORED_MODELS')
|
||||
|
||||
SUBMIT_VALUE_AS = get_setting('SUBMIT_VALUE_AS')
|
||||
|
||||
validate_submit_value_as(SUBMIT_VALUE_AS)
|
||||
|
|
|
|||
|
|
@ -97,14 +97,14 @@ class BaseBulkChangePluginsForm(forms.ModelForm):
|
|||
"""
|
||||
Bulk change plugins form.
|
||||
|
||||
- `selected_dashboard_plugins` (str): List of comma separated values to be
|
||||
- `selected_plugins` (str): List of comma separated values to be
|
||||
changed.
|
||||
- `users_action` (int): For indicating wheither the users shall be appended
|
||||
to the dashbard plugins or replaced.
|
||||
- `groups_action` (int): For indicating wheither the groups shall be
|
||||
appended to the dashboard plugins or replaced.
|
||||
"""
|
||||
selected_dashboard_plugins = forms.CharField(
|
||||
selected_plugins = forms.CharField(
|
||||
required=True, label=_("Selected plugins"),
|
||||
widget=forms.widgets.HiddenInput
|
||||
)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ __all__ = (
|
|||
'admin_change_url', 'uniquify_sequence', 'safe_text', 'combine_dicts',
|
||||
'update_plugin_data', 'get_select_field_choices',
|
||||
'validate_initial_for_choices', 'validate_initial_for_multiple_choices',
|
||||
'validate_submit_value_as',
|
||||
'validate_submit_value_as', 'get_app_label_and_model_name',
|
||||
)
|
||||
|
||||
import os
|
||||
|
|
@ -265,6 +265,17 @@ def get_registered_models(ignore=[]):
|
|||
|
||||
return registered_models
|
||||
|
||||
def get_app_label_and_model_name(path):
|
||||
"""
|
||||
Gets app_label and model_name from the path given.
|
||||
|
||||
:param str path: Dotted path to the model (without ".model", as stored
|
||||
in the Django `ContentType` model.
|
||||
:return tuple: app_label, model_name
|
||||
"""
|
||||
parts = path.split('.')
|
||||
return (''.join(parts[:-1]), parts[-1])
|
||||
|
||||
# *****************************************************************************
|
||||
# *****************************************************************************
|
||||
# ****************************** Admin helpers ********************************
|
||||
|
|
|
|||
Loading…
Reference in a new issue