Update conditions for more dynamic operators, choices, and value fields.

Review Request #8327 — Created Aug. 15, 2016 and submitted

Information

Djblets
release-0.10.x
67ffee5...

Reviewers

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 Board LocalSite along with the condition, for use in queries or
other function calls.

ConditionsField and ConditionsWidget 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 new BaseConditionOperator.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.

Description From Last Updated

This looks like it should probably be for choice in choices?

daviddavid
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/conditions/tests/test_values.py
        djblets/forms/widgets.py
        djblets/conditions/conditions.py
        djblets/conditions/choices.py
        djblets/conditions/tests/test_choices.py
        djblets/conditions/operators.py
        djblets/conditions/values.py
        djblets/forms/fields.py
        djblets/forms/tests/test_conditions_field.py
        djblets/conditions/tests/test_conditions.py
        djblets/conditions/tests/test_operators.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/conditions/tests/test_values.py
        djblets/forms/widgets.py
        djblets/conditions/conditions.py
        djblets/conditions/choices.py
        djblets/conditions/tests/test_choices.py
        djblets/conditions/operators.py
        djblets/conditions/values.py
        djblets/forms/fields.py
        djblets/forms/tests/test_conditions_field.py
        djblets/conditions/tests/test_conditions.py
        djblets/conditions/tests/test_operators.py
    
    
  2. 
      
david
  1. 
      
  2. djblets/forms/widgets.py (Diff revision 1)
     
     
     
     
    Show all issues

    This looks like it should probably be for choice in choices?

  3. 
      
chipx86
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/conditions/tests/test_values.py
        djblets/forms/widgets.py
        djblets/conditions/conditions.py
        djblets/conditions/choices.py
        djblets/conditions/tests/test_choices.py
        djblets/conditions/operators.py
        djblets/conditions/values.py
        djblets/forms/fields.py
        djblets/forms/tests/test_conditions_field.py
        djblets/conditions/tests/test_conditions.py
        djblets/conditions/tests/test_operators.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/conditions/tests/test_values.py
        djblets/forms/widgets.py
        djblets/conditions/conditions.py
        djblets/conditions/choices.py
        djblets/conditions/tests/test_choices.py
        djblets/conditions/operators.py
        djblets/conditions/values.py
        djblets/forms/fields.py
        djblets/forms/tests/test_conditions_field.py
        djblets/conditions/tests/test_conditions.py
        djblets/conditions/tests/test_operators.py
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-0.10.x (3bccd08)
Loading...