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.
-
In your description, "void of" should be "devoid of"
-
djblets/forms/forms/key_value_form.py (Diff revision 1) Instead of "list or tuple", how about "iterable"?
-
djblets/forms/forms/key_value_form.py (Diff revision 1) The final clause in this sentence is superfluous (you already said "the values from that instance").
-
-
-
Change Summary:
- Fixed wording in docs and change description.
- Switched to using
six.iterkeys
for iterating through the fields.
Description: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 2 (+553 -60) |

-
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
Change Summary:
Switched the for loop to
six.iteritems
, simplifying the code.
Diff: |
Revision 3 (+551 -60) |
---|

-
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