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:
TextAreaFieldCustom TextAreaField that converts its value with binary_type.
- class flask_mongoengine.wtf.fields.DictField(*args, **kwargs)[source]
Bases:
JSONFieldSpecial version fo
JSONFieldto be generated forflask_mongoengine.db_fields.DictField.Used in generator before flask_mongoengine version 2.0
- class flask_mongoengine.wtf.fields.EmptyStringIsNoneMixin[source]
Bases:
objectSpecial mixin to ignore empty strings before parent class processing.
Unlike old
NoneStringFieldwe 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:
TextAreaFieldSpecial version fo
wtforms.fields.TextAreaField.
- class flask_mongoengine.wtf.fields.ModelSelectField(*args, **kwargs)[source]
Bases:
QuerySetSelectFieldLike 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:
QuerySetSelectMultipleFieldAllows multiple select
- class flask_mongoengine.wtf.fields.MongoBooleanField(*args, **kwargs)[source]
Bases:
SelectFieldMongo 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.SelectFieldwith for Boolean values.Fully compatible with
wtforms.fields.SelectFieldand 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:
MongoTextAreaFieldForm 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
DictFieldConfiguration available with providing
wtf_optionsonDictFieldinitialization.- 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,EmailFieldRegular
wtforms.fields.EmailField, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoFloatField(*args, **kwargs)[source]
Bases:
FloatFieldRegular
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,HiddenFieldRegular
wtforms.fields.HiddenField, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoPasswordField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin,PasswordFieldRegular
wtforms.fields.PasswordField, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoSearchField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin,SearchFieldRegular
wtforms.fields.SearchField, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoStringField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin,StringFieldRegular
wtforms.fields.StringField, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoTelField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin,TelFieldRegular
wtforms.fields.TelField, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoTextAreaField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin,TextAreaFieldRegular
wtforms.fields.TextAreaField, that transform empty string to None.
- class flask_mongoengine.wtf.fields.MongoURLField(*args, **kwargs)[source]
Bases:
EmptyStringIsNoneMixin,URLFieldRegular
wtforms.fields.URLField, that transform empty string to None.
- class flask_mongoengine.wtf.fields.NoneStringField(*args, **kwargs)[source]
Bases:
StringFieldCustom StringField that counts “” as None
- class flask_mongoengine.wtf.fields.QuerySetSelectField(*args, **kwargs)[source]
Bases:
SelectFieldBaseGiven 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:
QuerySetSelectFieldSame as
QuerySetSelectFieldbut 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 aModelFormsubclass.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,
ModelConverteris used.
- Return type:
Module contents
WTFForms integration module init file.