validators module
- class fluent_anvil.validators.LengthValidator
Bases:
Validator
Validates that the length of the given value is within a given range.
This is suitable for types that the len() function can be applied to, e.g., strings, lists, sets, etc. The validation and __call__ dunder have an optional second parameter that determines whether the minimum length is enforced. This is useful if enforcing the minimum length depends on whether the form is about to be saved or just validated during filling. If it is saved, the minimum length requirement should be enforced (set second parameter to True). If the form is still being drafted (second parameter set to False) then the minimum length requirement shall only be enforced if the user has already written something. If minimum length shall always be enforced, just omit the second parameter.
- __init__(minlen, maxlen, msg_too_short: str, msg_too_long: str, **variables)
Initialize Validator.
- Parameters:
minlen – Minimum length of the given value. If None, the minimum length will not be validated and “minlen” will not be available to fluent.
maxlen – Maximum length of the given value. If None, the maximum length will not be validated and “maxlen” will not be available to fluent.
variables – Keyworded parameters that are passed on to fluent. The minlen and maxlen parameters are already included under the same name and therefore they do not have to be added manually.
- class fluent_anvil.validators.Validator
Bases:
object
Convenient validation mechanism with localized error messages.
- __init__(fct, msg_id: str, *args, **variables)
Initialize Validator.
- Parameters:
fct – Validation function. Shall return True if validation passed. False, otherwise.
msg_id – The message ID for fluent.
variables – Keyworded parameters that are passed on to fluent.
- chain(fct, msg_id: str, **variables)
Append another validation criterion.
- Parameters:
fct – Validation function. Shall return True if validation passed. False, Otherwise.
msg_id – The message ID for fluent.
variables – Keyworded parameters that are passed on to fluent.
- is_valid(value, *args, **kwargs)
Validate the given value. Return True if validation passed. False, otherwise.
- Parameters:
value – The value to validate.
args – Positional arguments to pass on to the validation function.
kwargs – Keyworded arguments to pass on to the validation function.
- validate(value, *args, **kwargs)
Validate the given value. Raise a ValidationError if not successful.
- Parameters:
value – The value to validate.
args – Positional arguments to pass on to the validation function.
kwargs – Keyworded arguments to pass on to the validation function.