diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 1cc1a4147..291d8ab7c 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -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
diff --git a/README.rst b/README.rst
index c37cf3d69..d81ef86ab 100644
--- a/README.rst
+++ b/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)
+ `__
+- `Select (drop-down)
+ `__
+- `Select model object (drop-down)
+ `__
+- `Select multiple (drop-down)
+ `__
+- `Select multiple model objects (drop-down)
+ `__
+
Available translations
===============================================
English is the primary language.
diff --git a/TODOS.rst b/TODOS.rst
index 9d7ee99e6..c3cc02733 100644
--- a/TODOS.rst
+++ b/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``.
diff --git a/docs/index.rst b/docs/index.rst
index 4dc652e9d..46f742a9f 100644
--- a/docs/index.rst
+++ b/docs/index.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)
+ `__
+- `Select (drop-down)
+ `__
+- `Select model object (drop-down)
+ `__
+- `Select multiple (drop-down)
+ `__
+- `Select multiple model objects (drop-down)
+ `__
+
Available translations
===============================================
English is the primary language.
diff --git a/setup.py b/setup.py
index ea77b5acc..eb575a2f7 100644
--- a/setup.py
+++ b/setup.py
@@ -63,7 +63,7 @@
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',
diff --git a/src/fobi/__init__.py b/src/fobi/__init__.py
index 19d4c22aa..3ce110132 100644
--- a/src/fobi/__init__.py
+++ b/src/fobi/__init__.py
@@ -1,6 +1,6 @@
__title__ = 'django-fobi'
-__version__ = '0.4.27'
-__build__ = 0x000030
+__version__ = '0.4.28'
+__build__ = 0x000031
__author__ = 'Artur Barseghyan '
__copyright__ = '2014-2015 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
diff --git a/src/fobi/admin.py b/src/fobi/admin.py
index f28e1dfcf..d4038f7a9 100644
--- a/src/fobi/admin.py
+++ b/src/fobi/admin.py
@@ -6,6 +6,7 @@
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 @@ def bulk_change_plugins(self, request):
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 @@ def bulk_change_plugins(self, request):
_('{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,
diff --git a/src/fobi/contrib/plugins/form_elements/fields/radio/README.rst b/src/fobi/contrib/plugins/form_elements/fields/radio/README.rst
index b2b8235a0..33c0f08d3 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/radio/README.rst
+++ b/src/fobi/contrib/plugins/form_elements/fields/radio/README.rst
@@ -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
+
+
diff --git a/src/fobi/contrib/plugins/form_elements/fields/radio/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/radio/fobi_form_elements.py
index 9f995bc00..04782247d 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/radio/fobi_form_elements.py
+++ b/src/fobi/contrib/plugins/form_elements/fields/radio/fobi_form_elements.py
@@ -69,14 +69,14 @@ def submit_plugin_form_data(self, form_entry, request, form):
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.
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select/README.rst b/src/fobi/contrib/plugins/form_elements/fields/select/README.rst
index ce67b5c71..9013cef13 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select/README.rst
+++ b/src/fobi/contrib/plugins/form_elements/fields/select/README.rst
@@ -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
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/select/fobi_form_elements.py
index 04a89052a..be9534790 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select/fobi_form_elements.py
+++ b/src/fobi/contrib/plugins/form_elements/fields/select/fobi_form_elements.py
@@ -70,14 +70,14 @@ def submit_plugin_form_data(self, form_entry, request, form):
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.
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_model_object/README.rst b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/README.rst
index 481b64d1b..9607f8db4 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select_model_object/README.rst
+++ b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/README.rst
@@ -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.
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_model_object/defaults.py b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/defaults.py
index 89ddadb6f..cd475e72b 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select_model_object/defaults.py
+++ b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/defaults.py
@@ -2,6 +2,10 @@
__author__ = 'Artur Barseghyan '
__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
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_model_object/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/fobi_form_elements.py
index 5c81a66ab..dd3b241ce 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select_model_object/fobi_form_elements.py
+++ b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/fobi_form_elements.py
@@ -10,10 +10,15 @@
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 @@ def get_form_field_instances(self):
"""
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 @@ def submit_plugin_form_data(self, form_entry, request, form):
: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
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_model_object/settings.py b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/settings.py
index 0b3a8189d..535ac749a 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select_model_object/settings.py
+++ b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/settings.py
@@ -2,9 +2,15 @@
__author__ = 'Artur Barseghyan '
__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)
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple/README.rst b/src/fobi/contrib/plugins/form_elements/fields/select_multiple/README.rst
index 2812e6af5..cf4d88c56 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select_multiple/README.rst
+++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple/README.rst
@@ -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
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple/fobi_form_elements.py
index a10e32dee..75d26506e 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select_multiple/fobi_form_elements.py
+++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple/fobi_form_elements.py
@@ -74,14 +74,14 @@ def submit_plugin_form_data(self, form_entry, request, form):
# 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)
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/README.rst b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/README.rst
index 5e6c98cc6..23056fad0 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/README.rst
+++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/README.rst
@@ -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.
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/conf.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/conf.py
index 45401829c..5ea74cc17 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/conf.py
+++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/conf.py
@@ -6,7 +6,8 @@
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):
"""
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/defaults.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/defaults.py
index 063e77766..dee92da14 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/defaults.py
+++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/defaults.py
@@ -2,6 +2,10 @@
__author__ = 'Artur Barseghyan '
__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
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/fobi_form_elements.py
index 7c7e0770d..926a0ca9a 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/fobi_form_elements.py
+++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/fobi_form_elements.py
@@ -12,12 +12,17 @@
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 @@ def get_form_field_instances(self):
"""
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 @@ def submit_plugin_form_data(self, form_entry, request, form):
: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.
diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/settings.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/settings.py
index 7291e6ed2..bd20364b5 100644
--- a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/settings.py
+++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/settings.py
@@ -2,9 +2,14 @@
__author__ = 'Artur Barseghyan '
__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)
diff --git a/src/fobi/forms.py b/src/fobi/forms.py
index 2bc81fb30..8e344547e 100644
--- a/src/fobi/forms.py
+++ b/src/fobi/forms.py
@@ -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
)
diff --git a/src/fobi/helpers.py b/src/fobi/helpers.py
index 8d760ecac..184c439ba 100644
--- a/src/fobi/helpers.py
+++ b/src/fobi/helpers.py
@@ -15,7 +15,7 @@
'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 ********************************