"""Conditions for Actions."""
from .js import JsDictMixin
[docs]class Condition(JsDictMixin):
"""Base condition."""
[docs] def validate(self, form):
"""Return True if the form passes this condition."""
[docs]class ValueIs(Condition):
"""Rule that passes if a field has an arbitrary value."""
def __init__(self, field, value):
"""Require a field to have a value."""
self.field = field
self.value = value
[docs] def validate(self, form):
"""Return True if the form field has the given value."""
return form.data.get(self.field, None) == self.value