Update conditions for more dynamic operators, choices, and value fields.
Review Request #8327 — Created Aug. 15, 2016 and submitted — Latest diff uploaded
This enhances the conditions support in order to allow choices,
operators, and value fields to allow for more dynamic logic and state.Choices can now take user-provided keyword arguments in the constructor,
which are saved and made available for use in matching or other
functions. This is handy for including such things as a request or
Review BoardLocalSite
along with the condition, for use in queries or
other function calls.
ConditionsField
andConditionsWidget
now accept these keyword arguments
for choices. They'll apply these to each choice being constructed. Forms
using this widget can set this in the form's constructor.A choice or operator's value fields can now be dynamically created. The
BaseConditionChoice.default_value_field
and
BaseConditionChoice.value_field
attributes can now be functions, which
could operate off of the extra state on the choice. This is useful for
creating querysets or initial values based on form-provided data.Choices can also now make use of existing operators but with
overridden data (such as the operator name displayed to the user). This
is done with a newBaseConditionOperator.with_overrides()
method,
which dynamically creates a new subclass with the overridden attributes.
It's a convenience over the caller having to create a bunch of tiny
subclasses just to replace the name.Upcoming changes will build upon this to offer improved choices and
operators for working with models and querysets.
Unit tests pass.
Tested manually with soem new choices/operators that make use of these
new dynamic capabilities, and verified that they performed as expected.