WTF module API
This is the flask_mongoengine.wtf modules API documentation.
flask_mongoengine.wtf.fields module
Useful form fields for use with the mongoengine.
- class flask_mongoengine.wtf.fields.BinaryField(*args, **kwargs)[source]
Bases:
TextAreaField
Custom TextAreaField that converts its value with binary_type.
- class flask_mongoengine.wtf.fields.DictField(*args, **kwargs)[source]
Bases:
JSONField
Special version fo
JSONField
to be generated forflask_mongoengine.db_fields.DictField
.Used in generator before flask_mongoengine version 2.0
- class flask_mongoengine.wtf.fields.EmptyStringIsNoneMixin[source]
Bases:
object
Special mixin to ignore empty strings before parent class processing.
Unlike old
NoneStringField
we do it before parent class call, this allows us to reuse this mixin in many more cases without errors.- process_formdata(valuelist)[source]
Ignores empty string and calls parent
process_formdata()
if data present.- Parameters
valuelist – A list of strings to process.
- class flask_mongoengine.wtf.fields.JSONField(*args, **kwargs)[source]
Bases:
TextAreaField
Special version fo
wtforms.fields.TextAreaField
.
- class flask_mongoengine.wtf.fields.ModelSelectField(*args, **kwargs)[source]
Bases:
QuerySetSelectField
Like a QuerySetSelectField, except takes a model class instead of a queryset and lists everything in it.
- class flask_mongoengine.wtf.fields.ModelSelectMultipleField(*args, **kwargs)[source]
Bases:
QuerySetSelectMultipleField
Allows multiple select
- class flask_mongoengine.wtf.fields.MongoBooleanField(*args, **kwargs)[source]
Bases:
SelectField
Mongo SelectField field for BooleanFields, that correctly coerce values.
- __init__(label=None, validators=None, coerce=None, choices=None, validate_choice=True, **kwargs)[source]
Replaces defaults of
wtforms.fields.SelectField
with for Boolean values.Fully compatible with
wtforms.fields.SelectField
and have same parameters.
- class flask_mongoengine.wtf.fields.MongoDictField(json_encoder=None, json_encoder_kwargs=None, json_decoder=None, json_decoder_kwargs=None, null=None, *args, **kwargs)[source]
Bases:
MongoTextAreaField
Form field to handle JSON in
DictField
.- __init__(json_encoder=None, json_encoder_kwargs=None, json_decoder=None, json_decoder_kwargs=None, null=None, *args, **kwargs)[source]
Special WTForms field for
DictField
Configuration available with providing
wtf_options
onDictField
initialization.- Parameters
json_encoder (
Optional
[Callable
]) – Any function, capable to transform dict to string, by defaultjson.dumps()
json_encoder_kwargs (
Optional
[dict
]) – Any dictionary with parameters tojson_encoder()
, by default: {“indent”:4}json_decoder (
Optional
[Callable
]) – Any function, capable to transform string to dict, by defaultjson.loads()
json_decoder_kwargs (
Optional
[dict
]) – Any dictionary with parameters tojson_decoder()
, by default: {}
- class flask_mongoengine.wtf.fields.MongoEmailField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin
,EmailField
Regular
wtforms.fields.EmailField
, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoFloatField(*args, **kwargs)[source]
Bases:
FloatField
Regular
wtforms.fields.FloatField
, with widget replaced towtforms.widgets.NumberInput
.- widget = <wtforms.widgets.core.NumberInput object>
- class flask_mongoengine.wtf.fields.MongoHiddenField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin
,HiddenField
Regular
wtforms.fields.HiddenField
, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoPasswordField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin
,PasswordField
Regular
wtforms.fields.PasswordField
, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoSearchField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin
,SearchField
Regular
wtforms.fields.SearchField
, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoStringField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin
,StringField
Regular
wtforms.fields.StringField
, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoTelField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin
,TelField
Regular
wtforms.fields.TelField
, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoTextAreaField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin
,TextAreaField
Regular
wtforms.fields.TextAreaField
, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoURLField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin
,URLField
Regular
wtforms.fields.URLField
, that transform empty string to None.
- class flask_mongoengine.wtf.fields.NoneStringField(*args, **kwargs)[source]
Bases:
StringField
Custom StringField that counts “” as None
- class flask_mongoengine.wtf.fields.QuerySetSelectField(*args, **kwargs)[source]
Bases:
SelectFieldBase
Given a QuerySet either at initialization or inside a view, will display a select drop-down field of choices. The data property actually will store/keep an ORM model instance, not the ID. Submitting a choice which is not in the queryset will result in a validation error.
Specifying label_attr in the constructor will use that property of the model instance for display in the list, else the model object’s __str__ or __unicode__ will be used.
If allow_blank is set to True, then a blank choice will be added to the top of the list. Selecting this choice will result in the data property being None. The label for the blank choice can be set by specifying the blank_text parameter.
- __init__(label='', validators=None, queryset=None, label_attr='', allow_blank=False, blank_text='---', label_modifier=None, **kwargs)[source]
Init docstring placeholder.
- iter_choices()[source]
Provides data for choice widget rendering. Must return a sequence or iterable of (value, label, selected) tuples.
- pre_validate(form)[source]
Field-level validation. Runs before any other validators.
- Parameters
form – The form the field belongs to.
- process_formdata(valuelist)[source]
Process data received over the wire from a form.
This will be called during form construction with data supplied through the formdata argument.
- Parameters
valuelist – A list of strings to process.
- widget = <wtforms.widgets.core.Select object>
- class flask_mongoengine.wtf.fields.QuerySetSelectMultipleField(*args, **kwargs)[source]
Bases:
QuerySetSelectField
Same as
QuerySetSelectField
but with multiselect options.- __init__(label='', validators=None, queryset=None, label_attr='', allow_blank=False, blank_text='---', **kwargs)[source]
Init docstring placeholder.
- process_formdata(valuelist)[source]
Process data received over the wire from a form.
This will be called during form construction with data supplied through the formdata argument.
- Parameters
valuelist – A list of strings to process.
- widget = <wtforms.widgets.core.Select object>
flask_mongoengine.wtf.models module
flask_mongoengine.wtf.orm module
Tools for generating forms based on mongoengine Document schemas.
- flask_mongoengine.wtf.orm._get_fields_names(model, only, exclude)[source]
Filter fields names for further form generation.
- Parameters
- Return type
- flask_mongoengine.wtf.orm.model_fields(model, only=None, exclude=None, field_args=None, converter=None)[source]
Generate a dictionary of fields for a given database model.
See
model_form()
docstring for description of parameters.- Return type
- flask_mongoengine.wtf.orm.model_form(model, base_class=<class 'flask_mongoengine.wtf.models.ModelForm'>, only=None, exclude=None, field_args=None, converter=None)[source]
Create a wtforms Form for a given mongoengine Document schema:
from flask_mongoengine.wtf import model_form from myproject.myapp.schemas import Article ArticleForm = model_form(Article)
- Parameters
model (
Type
[BaseDocument
]) – A mongoengine Document schema classbase_class (
Type
[ModelForm
]) – Base form class to extend from. Must be aModelForm
subclass.only (
Optional
[List
[str
]]) – An optional iterable with the property names that should be included in the form. Only these properties will have fields. Fields are always appear in provided order, this allows user to change form fields ordering, without changing database model.exclude (
Optional
[List
[str
]]) – An optional iterable with the property names that should be excluded from the form. All other properties will have fields. Fields are appears in order, defined in model, excluding provided fields names. For adjusting fields ordering, useonly
.field_args – An optional dictionary of field names mapping to keyword arguments used to construct each field object.
converter – A converter to generate the fields based on the model properties. If not set,
ModelConverter
is used.
- Return type
Module contents
WTFForms integration module init file.