Add a form for working with key/value stores instead of models.
Review Request #7853 — Created Jan. 7, 2016 and submitted
Forms generally are bound to models, or are completely custom and devoid
of any real default logic beyond rendering and validation. We have some
forms in Djblets that interface with models or other objects, treating
them like key/value stores usingset
andget
methods. These are
all based onSiteSettingsForm
, which is built forSiteConfiguration
,
and isn't always the best model to use.This change introduces a new form,
KeyValueForm
, which works as a base
for all these other forms,SiteSettingsForm
included. It handles the
loading of data from an object, the saving of form data back out to
the object, and load/save blacklists for fields (a feature used by
these other forms). It also handles easily marking some fields as
disabled, another feature used by these other forms.It's built to be usable with any type of key/value storage backend,
by providing several functions that can be overridden to handle the
getting and setting of keys and their values and the creation/saving
of instances.
Unit tests pass in both Djblets and Review Board.
Manually tested configuring extensions and saving the various site
settings forms.
- Change Summary:
-
- Fixed wording in docs and change description.
- Switched to using
six.iterkeys
for iterating through the fields.
- Description:
-
~ Forms generally are bound to models, or are completely custom and void
~ Forms generally are bound to models, or are completely custom and devoid
of any real default logic beyond rendering and validation. We have some forms in Djblets that interface with models or other objects, treating them like key/value stores using set
andget
methods. These areall based on SiteSettingsForm
, which is built forSiteConfiguration
,and isn't always the best model to use. This change introduces a new form,
KeyValueForm
, which works as a basefor all these other forms, SiteSettingsForm
included. It handles theloading of data from an object, the saving of form data back out to the object, and load/save blacklists for fields (a feature used by these other forms). It also handles easily marking some fields as disabled, another feature used by these other forms. It's built to be usable with any type of key/value storage backend,
by providing several functions that can be overridden to handle the getting and setting of keys and their values and the creation/saving of instances.
-
Tool: Pyflakes Processed Files: djblets/extensions/forms.py djblets/forms/tests/test_key_value_form.py djblets/forms/forms/key_value_form.py djblets/siteconfig/forms.py djblets/forms/forms/__init__.py Ignored Files: djblets/forms/tests/__init__.py Tool: PEP8 Style Checker Processed Files: djblets/extensions/forms.py djblets/forms/tests/test_key_value_form.py djblets/forms/forms/key_value_form.py djblets/siteconfig/forms.py djblets/forms/forms/__init__.py Ignored Files: djblets/forms/tests/__init__.py
-
Tool: Pyflakes Processed Files: djblets/extensions/forms.py djblets/forms/tests/test_key_value_form.py djblets/forms/forms/key_value_form.py djblets/siteconfig/forms.py djblets/forms/forms/__init__.py Ignored Files: djblets/forms/tests/__init__.py Tool: PEP8 Style Checker Processed Files: djblets/extensions/forms.py djblets/forms/tests/test_key_value_form.py djblets/forms/forms/key_value_form.py djblets/siteconfig/forms.py djblets/forms/forms/__init__.py Ignored Files: djblets/forms/tests/__init__.py