Add a form field for configuring conditions.
Review Request #8279 — Created July 11, 2016 and submitted
This introduces a new Django form field that allows users to view and configure conditions. This is presented as a JavaScript-backed widget that shows each condition as a row containing drop-downs for the choice and operator, and a field for the value. Below these are a button for adding new condition rows. Changing a choice will change the list of operators available, and reset the value for the new type of field. Changing just the operator will retain the value unless the new or old operators had a custom value field. Conditions can be deleted by clicking a "-" button on the left of the row. The widget is designed to handle form validation and to be resilient to missing choices/operators (which could happen if working with conditions that were based on choices/operators from extensions). Errors specific to a condition (value validation issues, for instance) will show up in the row for that condition, and will be resolved once corrected and the form re-submitted. Missing condition choices/operators will result in a disabled condition row, which must be deleted before the form can be submitted again.
Tested loading/editing existing conditions, adding new ones, and deleting
them.Tested custom value fields on both choices and operators.
Tested choices/operators that don't need a value.
Tested that the value was preserved when switching operators within a choice,
unless the old/new operator had a custom value field.Tested validation errors for value fields.
Tested usage of extension-provided custom choices/operators.
Tested missing choice/operators, their presentation, and inability to save
until the conditions were removed.Unit tests pass.
Description | From | Last Updated |
---|---|---|
These aren't quite all aligned vertically. Have fun! |
brennie | |
It doesn't actually matter but I think it would be conceptually nicer to do this after choices has been validated. |
david | |
The first comma in here is unnecessary. |
david | |
serialized as a dict ? |
brennie | |
Should we assert isinstance(data, dict) after this? |
brennie | |
Module docstring? |
david | |
list comprehension redefines 'choice' from line 220 |
reviewbot | |
This has a bunch of selectors that are nested deeper than they need to be. Everything that starts with conditions- … |
david | |
Doc comment? |
david | |
Do you really want this to run on every change to every property or should it be this.on('change:choice', ...? |
david | |
Mind moving these down closer to where they're used? |
david | |
Same with this? |
david | |
Parens aren't needed when there's just one argument. |
david | |
Parens aren't needed when there's just one argument. |
david | |
Parens aren't needed when there's just one argument. |
david | |
Parens around this expression aren't needed. |
david | |
Col: 80 E501 line too long (81 > 79 characters) |
reviewbot | |
I don't see this file listed in the diff. |
david | |
Col: 80 E501 line too long (83 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (83 > 79 characters) |
reviewbot |
-
-
It doesn't actually matter but I think it would be conceptually nicer to do this after
choices
has been validated. -
-
-
This has a bunch of selectors that are nested deeper than they need to be. Everything that starts with
conditions-
can be pulled out to the top level with no loss of specificity. -
-
Do you really want this to run on every change to every property or should it be
this.on('change:choice', ...
? -
-
-
-
-
-
-
- Change Summary:
-
- Removed a reference to a non-existent (and unneeded) unit test file.
- Cleaned up some docs and comments.
- Added missing docstrings for functions and file headers.
- Sanity-checked data being passed to a
ConditionsField
, raising an error if the end result isn't adict
. - Fixed vertical alignment of mode radio buttons.
- Fixed a bad lookup in the JavaScript for conditions with an invalid choice ID, and added a unit test.
- Removed parens for single-arg fat arrow functions when inside a function call.
- Other misc code cleanups.
- Commit:
-
c8c45c79425218b91302cb5cb391206c992aaf4b67b270a9e806a8c5606bcddafed59c70c288bdee
- Diff:
-
Revision 2 (+3443)
- Added Files:
-
Tool: Pyflakes Processed Files: djblets/forms/widgets.py djblets/forms/tests/test_conditions_field.py djblets/staticbundles.py djblets/forms/fields.py djblets/forms/tests/test_conditions_widget.py Ignored Files: djblets/static/djblets/js/forms/views/tests/conditionValueFormFieldViewTests.es6.js djblets/static/djblets/js/forms/models/conditionValueField.es6.js djblets/static/djblets/js/forms/models/tests/conditionModelTests.es6.js djblets/static/djblets/js/forms/models/tests/conditionOperatorModelTests.es6.js djblets/static/djblets/js/forms/base.js djblets/static/djblets/js/forms/models/conditionSetModel.es6.js djblets/static/djblets/js/forms/models/conditionModel.es6.js djblets/static/djblets/js/forms/views/tests/conditionSetViewTests.es6.js djblets/static/djblets/js/forms/views/baseConditionValueFieldView.es6.js djblets/static/djblets/js/forms/models/conditionOperatorModel.es6.js djblets/static/djblets/js/forms/models/conditionChoiceModel.es6.js djblets/forms/templates/djblets_forms/conditions_widget.html djblets/static/djblets/js/forms/models/tests/conditionChoiceModelTests.es6.js djblets/static/djblets/js/forms/views/conditionValueFormFieldView.es6.js djblets/static/djblets/js/forms/views/conditionSetView.es6.js djblets/static/djblets/js/forms/models/tests/conditionSetModelTests.es6.js djblets/static/djblets/css/forms/conditions.less djblets/static/djblets/js/jquery.gravy.util.js Tool: PEP8 Style Checker Processed Files: djblets/forms/widgets.py djblets/forms/tests/test_conditions_field.py djblets/staticbundles.py djblets/forms/fields.py djblets/forms/tests/test_conditions_widget.py Ignored Files: djblets/static/djblets/js/forms/views/tests/conditionValueFormFieldViewTests.es6.js djblets/static/djblets/js/forms/models/conditionValueField.es6.js djblets/static/djblets/js/forms/models/tests/conditionModelTests.es6.js djblets/static/djblets/js/forms/models/tests/conditionOperatorModelTests.es6.js djblets/static/djblets/js/forms/base.js djblets/static/djblets/js/forms/models/conditionSetModel.es6.js djblets/static/djblets/js/forms/models/conditionModel.es6.js djblets/static/djblets/js/forms/views/tests/conditionSetViewTests.es6.js djblets/static/djblets/js/forms/views/baseConditionValueFieldView.es6.js djblets/static/djblets/js/forms/models/conditionOperatorModel.es6.js djblets/static/djblets/js/forms/models/conditionChoiceModel.es6.js djblets/forms/templates/djblets_forms/conditions_widget.html djblets/static/djblets/js/forms/models/tests/conditionChoiceModelTests.es6.js djblets/static/djblets/js/forms/views/conditionValueFormFieldView.es6.js djblets/static/djblets/js/forms/views/conditionSetView.es6.js djblets/static/djblets/js/forms/models/tests/conditionSetModelTests.es6.js djblets/static/djblets/css/forms/conditions.less djblets/static/djblets/js/jquery.gravy.util.js
-