Fields¶
Fields represent a set of rules to data validation via set of Validator
instances. When you define yours
custom Form
you define Fields as its class attributes.
This is the most common usage of Fields, but nothing prevents you to use them standalone.
Field class¶
-
class
flyforms.fields.
Field
[source]¶ Construction
-
__init__
(required=True, choices=(), validators=(), **kwargs)[source]¶ Parameters: - required (bool) – boolean flag is this field required or can be empty
- choices (iterable) – iterable object contains possible values of this field
- validators (list of callable) – the additional validators for field
- default (instance of value_types) – the default value of the field
Raises TypeError: if passed arguments invalid
Methods
-
validate
(value)[source]¶ Validates given value via defined set of
Validators
Parameters: value – the value to validate
-
is_valid
(value)[source]¶ The ‘silent’ variant of value validation.
Parameters: value – the value to validate Returns: True if given value is valid, otherwise - False
-
bind
(value)[source]¶ Validates and given value via defined set of
Validators
and returns itParameters: value – the value to bind Returns: given value or field.default
if value isUNSET
New in version 0.2.0.
Attributes
-
required
¶ Boolean flag passed to constructor
-
base_validators
¶ List of attached by processing construction arguments
Validators
-
custom_validators
¶ Iterable object contains
custom_validators
passed to constructor
Property
-
validators
¶ Chain, contains
base_validators
andcustom_validators
-
Basic Fields¶
StringField¶
-
class
flyforms.fields.
StringField
(min_length=None, max_length=None, regex='', **kwargs)[source]¶ Reflects Python strings
-
__init__
(min_length=None, max_length=None, regex='', **kwargs)[source]¶ Parameters: - required (bool) – boolean flag is this field required
- min_length (int or None) – the minimum length of the string
- max_length (int or None) – the maximum length of the string
- regex (str or regexp) – the regular expression to validate
- choices (iterable) – iterable object contains possible values of this field
- validators (list of callable) – the additional validators for field
- default (instance of value_types) – the default value of the field
-
EmailField¶
-
class
flyforms.fields.
EmailField
(**kwargs)[source]¶ Reflects Python string corresponding to an email
-
__init__
(**kwargs)[source]¶ Parameters: - required (bool) – boolean flag is this field required
- choices (iterable) – iterable object contains possible values of this field
- validators (list of callable) – the additional validators for field
- default (instance of value_types) – the default value of the field
-
IntField¶
-
class
flyforms.fields.
IntField
(min_value=None, max_value=None, **kwargs)[source]¶ Reflects Python integer (
int
)-
__init__
(min_value=None, max_value=None, **kwargs)[source]¶ Parameters: - required (bool) – boolean flag is this field required
- min_value – the minimum valid value
- max_value – the maximum valid value
- choices (iterable) – iterable object contains possible values of this field
- validators (list of callable) – the additional validators for field
- default (instance of value_types) – the default value of the field
-
FloatField¶
-
class
flyforms.fields.
FloatField
(min_value=None, max_value=None, **kwargs)[source]¶ Reflects Python float (
float
)-
__init__
(min_value=None, max_value=None, **kwargs)¶ Parameters: - required (bool) – boolean flag is this field required
- min_value – the minimum valid value
- max_value – the maximum valid value
- choices (iterable) – iterable object contains possible values of this field
- validators (list of callable) – the additional validators for field
- default (instance of value_types) – the default value of the field
-
Ip4Field¶
-
class
flyforms.fields.
Ip4Field
(**kwargs)[source]¶ Reflects Python string corresponding to an IPv4 address
-
__init__
(**kwargs)[source]¶ Parameters: - required (bool) – boolean flag is this field required
- choices (iterable) – iterable object contains possible values of this field
- validators (list of callable) – the additional validators for field
- default (instance of value_types) – the default value of the field
-
Schema Field¶
Schema Fields is a set of rules to validation data structures such as lists, dicts.
ListField¶
-
class
flyforms.fields.
ListField
(min_length=None, max_length=None, jsonify=True, **kwargs)[source]¶ Reflects iterable Python objects
-
__init__
(min_length=None, max_length=None, jsonify=True, **kwargs)[source]¶ Parameters: - min_length – minimum iterable length
- max_length – maximum iterable length
- jsonify – if passed
item_type
should be one ofjsonify_types
- kwargs – basic
Field
parameters
-