Skip to content

Commit

Permalink
prepare 0.4.28; fix improperly picked configuration of select_multipl…
Browse files Browse the repository at this point in the history
…e_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
  • Loading branch information
barseghyanartur committed Mar 13, 2015
1 parent 123ca3c commit 888646c
Show file tree
Hide file tree
Showing 24 changed files with 331 additions and 55 deletions.
25 changes: 18 additions & 7 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:

Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions TODOS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand All @@ -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``.
Expand Down
31 changes: 31 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/fobi/__init__.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
8 changes: 8 additions & 0 deletions src/fobi/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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,
Expand Down
51 changes: 51 additions & 0 deletions src/fobi/contrib/plugins/form_elements/fields/radio/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions src/fobi/contrib/plugins/form_elements/fields/select/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
__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

0 comments on commit 888646c

Please sign in to comment.