Advanced usage
This section provides advanced usages of FlyForms such as Custom Fields
and Custom Validators.
Custom Fields
Sometimes, it is necessary to design custom fields for validation of some special data structures.
If you want do this, you should design your custom subclass of the Field class.
Field class
-
class
flyforms.fields.
Field
[source]
This the base class for all Fields.
:: automethod:: __init__
-
validate
(value)[source]
This is base validation of given value (type, required and choices checks)
Parameters: | value (any) – the value to validate |
Raise: | ValidationError with first error occurred during validation |
-
is_valid
(value)[source]
The ‘silent’ variant of value validation.
Parameters: | value (any) – the value to validate |
Returns: | True if given value is valid, otherwise - False |
Return type: | bool |
Custom Validators
If you need to make additional data validation you can use your custom validators.
There is one requirement: validator should be an initialized and callable object.
If you want, you can use and extend one of this classes: Validator or Simple Validator.
Validator
-
class
flyforms.validators.
Validator
[source]
This the base class for all Fields.
-
validate
(value)[source]
Validate the given value
Parameters: | value – given value to validate |
:raise ValidationError if given value is not valid
-
is_valid
(value)[source]
The ‘silent’ variant of validation
Parameters: | value – given value to validate |
Returns: | boolean flag is given value valid |
Return type: | bool |
Simple Validator
-
class
flyforms.validators.
SimpleValidator
[source]
The Validator’s subclass with only one validation case.
Given value should satisfies condition in positive_case method