Base module API
This is the flask_mongoengine main modules API documentation.
flask_mongoengine.connection module
Module responsible for connection setup.
- flask_mongoengine.connection._get_name(setting_name)[source]
Return known pymongo setting name, or lower case name for unknown.
This problem discovered in issue #451. As mentioned there pymongo settings are not case-sensitive, but mongoengine use exact name of some settings for matching, overwriting pymongo behaviour.
This function address this issue, and potentially address cases when pymongo will become case-sensitive in some settings by same reasons as mongoengine done.
Based on pymongo 4.1.1 settings.
- Return type
- flask_mongoengine.connection._sanitize_settings(settings)[source]
Remove
MONGODB_
prefix from dict values, to correct bypass to mongoengine.- Return type
- flask_mongoengine.connection.create_connections(config)[source]
Given Flask application’s config dict, extract relevant config vars out of it and establish MongoEngine connection(s) based on them.
- flask_mongoengine.connection.get_connection_settings(config)[source]
Given a config dict, return a sanitized dict of MongoDB connection settings that we can then use to establish connections. For new applications, settings should exist in a
MONGODB_SETTINGS
key, but for backward compatibility we also support several config keys prefixed byMONGODB_
, e.g.MONGODB_HOST
,MONGODB_PORT
, etc.
flask_mongoengine.db_fields module
Responsible for mongoengine fields extension, if WTFForms integration used.
- class flask_mongoengine.db_fields.BinaryField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,BinaryField
Extends
mongoengine.fields.BinaryField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- DEFAULT_WTF_FIELD
alias of
BinaryField
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.BooleanField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,BooleanField
Extends
mongoengine.fields.BooleanField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- DEFAULT_WTF_FIELD
alias of
MongoBooleanField
- class flask_mongoengine.db_fields.CachedReferenceField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,CachedReferenceField
Extends
mongoengine.fields.CachedReferenceField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.ComplexDateTimeField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,ComplexDateTimeField
Extends
mongoengine.fields.ComplexDateTimeField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
Important
During WTForm generation this field uses
wtforms.fields.DateTimeLocalField
with milliseconds accuracy. Direct microseconds not supported by browsers for this type of field. If exact microseconds support required, please usewtforms.fields.DateTimeField
with extended text format set. Examples available in example app.This does not affect on in database accuracy.
- DEFAULT_WTF_FIELD
alias of
DateTimeLocalField
- class flask_mongoengine.db_fields.DateField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,DateField
Extends
mongoengine.fields.DateField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- class flask_mongoengine.db_fields.DateTimeField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,DateTimeField
Extends
mongoengine.fields.DateTimeField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- DEFAULT_WTF_FIELD
alias of
DateTimeLocalField
- class flask_mongoengine.db_fields.DecimalField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,DecimalField
Extends
mongoengine.fields.DecimalField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- DEFAULT_WTF_FIELD
alias of
DecimalField
- property wtf_generated_options: dict
Extend form validators with
wtforms.validators.NumberRange
.- Return type
- class flask_mongoengine.db_fields.DictField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,DictField
Extends
mongoengine.fields.DictField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- DEFAULT_WTF_FIELD
alias of
MongoDictField
- class flask_mongoengine.db_fields.DynamicField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,DynamicField
Extends
mongoengine.fields.DynamicField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.EmailField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,EmailField
Extends
mongoengine.fields.EmailField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
Changed in version 2.0.0: Default form field output changed from
NoneStringField
toflask_mongoengine.wtf.fields.MongoEmailField
- DEFAULT_WTF_FIELD
alias of
MongoEmailField
- property wtf_generated_options: dict
Extend form validators with
wtforms.validators.Email
- Return type
- class flask_mongoengine.db_fields.EmbeddedDocumentField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,EmbeddedDocumentField
Extends
mongoengine.fields.EmbeddedDocumentField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.EmbeddedDocumentListField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,EmbeddedDocumentListField
Extends
mongoengine.fields.EmbeddedDocumentListField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.EnumField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,EnumField
Extends
mongoengine.fields.EnumField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.FileField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,FileField
Extends
mongoengine.fields.FileField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.FloatField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,FloatField
Extends
mongoengine.fields.FloatField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
Changed in version 2.0.0: Default form field output changed from
wtforms.fields.FloatField
toflask_mongoengine.wtf.fields.MongoFloatField
with ‘numbers’ input type.- DEFAULT_WTF_FIELD
alias of
MongoFloatField
- property wtf_generated_options: dict
Extend form validators with
wtforms.validators.NumberRange
.- Return type
- class flask_mongoengine.db_fields.GenericEmbeddedDocumentField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,GenericEmbeddedDocumentField
Extends
mongoengine.fields.GenericEmbeddedDocumentField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.GenericLazyReferenceField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,GenericLazyReferenceField
Extends
mongoengine.fields.GenericLazyReferenceField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.GenericReferenceField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,GenericReferenceField
Extends
mongoengine.fields.GenericReferenceField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.GeoJsonBaseField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,GeoJsonBaseField
Extends
mongoengine.fields.GeoJsonBaseField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.GeoPointField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,GeoPointField
Extends
mongoengine.fields.GeoPointField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.ImageField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,ImageField
Extends
mongoengine.fields.ImageField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.IntField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,IntField
Extends
mongoengine.fields.IntField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- DEFAULT_WTF_FIELD
alias of
IntegerField
- property wtf_generated_options: dict
Extend form validators with
wtforms.validators.NumberRange
.- Return type
- class flask_mongoengine.db_fields.LazyReferenceField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,LazyReferenceField
Extends
mongoengine.fields.LazyReferenceField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.LineStringField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,LineStringField
Extends
mongoengine.fields.LineStringField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.ListField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,ListField
Extends
mongoengine.fields.ListField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.LongField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,LongField
Extends
mongoengine.fields.LongField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.MapField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,MapField
Extends
mongoengine.fields.MapField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.MultiLineStringField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,MultiLineStringField
Extends
mongoengine.fields.MultiLineStringField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.MultiPointField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,MultiPointField
Extends
mongoengine.fields.MultiPointField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.MultiPolygonField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,MultiPolygonField
Extends
mongoengine.fields.MultiPolygonField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.ObjectIdField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,ObjectIdField
Extends
mongoengine.fields.ObjectIdField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.PointField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,PointField
Extends
mongoengine.fields.PointField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.PolygonField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,PolygonField
Extends
mongoengine.fields.PolygonField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.ReferenceField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,ReferenceField
Extends
mongoengine.fields.ReferenceField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- DEFAULT_WTF_FIELD
alias of
ModelSelectField
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.SequenceField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,SequenceField
Extends
mongoengine.fields.SequenceField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.SortedListField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,SortedListField
Extends
mongoengine.fields.SortedListField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.StringField(*, password=False, textarea=False, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,StringField
Extends
mongoengine.fields.StringField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
Changed in version 2.0.0: Default form field output changed from
NoneStringField
toflask_mongoengine.wtf.fields.MongoTextAreaField
- DEFAULT_WTF_FIELD
alias of
MongoTextAreaField
- __init__(*, password=False, textarea=False, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Extended
__init__()
method for mongoengine db field with WTForms options.- Parameters
password (
bool
) – DEPRECATED: Force to useMongoPasswordField
for field generation. In case ofpassword
andwtf_field_class
both set, thenwtf_field_class
will be used.textarea (
bool
) – DEPRECATED: Force to useMongoTextAreaField
for field generation. In case oftextarea
andwtf_field_class
both set, thenwtf_field_class
will be used.filters (
Union
[List
,Callable
,None
]) – DEPRECATED: wtf form field filters.validators (
Union
[List
,Callable
,None
]) – DEPRECATED: wtf form field validators.wtf_field_class (
Optional
[Type
]) – Any subclass ofwtforms.forms.core.Field
that can be used for form field generation. Takes precedence overDEFAULT_WTF_FIELD
andDEFAULT_WTF_CHOICES_FIELD
wtf_filters (
Union
[List
,Callable
,None
]) – wtf form field filters.wtf_validators (
Union
[List
,Callable
,None
]) – wtf form field validators.wtf_choices_coerce (
Optional
[Callable
]) – Callable function to replaceDEFAULT_WTF_CHOICES_COERCE
for choices fields.wtf_options (
Optional
[dict
]) – Dictionary with WTForm Field settings. Applied last, takes precedence over any generated field options.kwargs – keyword arguments silently bypassed to normal mongoengine fields
- property wtf_field_class: Type
Parent class overwrite with support of class adjustment by field size.
- Return type
- property wtf_generated_options: dict
Extend form validators with
wtforms.validators.Regexp
andwtforms.validators.Length
.- Return type
- class flask_mongoengine.db_fields.URLField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,URLField
Extends
mongoengine.fields.URLField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
Changed in version 2.0.0: Default form field output changed from
NoneStringField
toMongoURLField
Changed in version 2.0.0: Now appends
Regexp
and use regexp provided to __init__url_regex
, instead of using non-configurable regexp fromURL
. This includes configuration conflicts, between modules.- DEFAULT_WTF_FIELD
alias of
MongoURLField
- property wtf_generated_options: dict
Extend form validators with
wtforms.validators.Regexp
- Return type
- class flask_mongoengine.db_fields.UUIDField(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
WtfFieldMixin
,UUIDField
Extends
mongoengine.fields.UUIDField
with wtf required parameters.For full list of arguments and keyword arguments, look parent field docs. All arguments should be passed as keyword arguments, to exclude unexpected behaviour.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Protection from execution of
to_wtf_field()
in form generation.- Raises
NotImplementedError – Field converter to WTForm Field not implemented.
- class flask_mongoengine.db_fields.WtfFieldMixin(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Bases:
object
Extension wrapper class for mongoengine BaseField.
This enables flask-mongoengine wtf to extend the number of field parameters, and settings on behalf of document model form generator for WTForm.
Class variables:
- Variables
DEFAULT_WTF_CHOICES_FIELD – Default WTForms Field used for db fields when choices option specified.
DEFAULT_WTF_FIELD – Default WTForms Field used for db field.
- DEFAULT_WTF_CHOICES_FIELD
alias of
SelectField
- DEFAULT_WTF_FIELD = None
- __init__(*, validators=None, filters=None, wtf_field_class=None, wtf_filters=None, wtf_validators=None, wtf_choices_coerce=None, wtf_options=None, **kwargs)[source]
Extended
__init__()
method for mongoengine db field with WTForms options.- Parameters
filters (
Union
[List
,Callable
,None
]) – DEPRECATED: wtf form field filters.validators (
Union
[List
,Callable
,None
]) – DEPRECATED: wtf form field validators.wtf_field_class (
Optional
[Type
]) – Any subclass ofwtforms.forms.core.Field
that can be used for form field generation. Takes precedence overDEFAULT_WTF_FIELD
andDEFAULT_WTF_CHOICES_FIELD
wtf_filters (
Union
[List
,Callable
,None
]) – wtf form field filters.wtf_validators (
Union
[List
,Callable
,None
]) – wtf form field validators.wtf_choices_coerce (
Optional
[Callable
]) – Callable function to replaceDEFAULT_WTF_CHOICES_COERCE
for choices fields.wtf_options (
Optional
[dict
]) – Dictionary with WTForm Field settings. Applied last, takes precedence over any generated field options.kwargs – keyword arguments silently bypassed to normal mongoengine fields
- static _ensure_callable_or_list(argument, msg_flag)[source]
Ensure submitted argument value is a callable object or valid list value.
- to_wtf_field(*, model=None, field_kwargs=None)[source]
Default WTFFormField generator for most of the fields.
- Parameters
model (
Optional
[Type
]) – Document of model fromdocuments
, passed byto_wtf_form()
for field types with other Document type dependency signature compatibility.field_kwargs (
Optional
[dict
]) – Final field generation adjustments, passed for custom Forms generation fromto_wtf_form()
fields_kwargs
parameter.
- property wtf_field_class: Type
Final WTForm Field class, that will be used for field generation.
- Return type
- property wtf_field_options: dict
Final WTForm Field options that will be applied as
wtf_field_class
kwargs.Can be overwritten by
to_wtf_field()
ifto_wtf_form()
called with related field name infields_kwargs
.It is not recommended to overwrite this property, for logic update overwrite
wtf_generated_options
- Return type
- flask_mongoengine.db_fields._setup_numbers_common_validators(options, obj)[source]
Extend
base_options
with common validators for number types.- Parameters
options (
dict
) – dict, usually fromWtfFieldMixin.wtf_generated_options
obj (
Union
[IntField
,DecimalField
,FloatField
]) – Anymongoengine.fields.IntField
ormongoengine.fields.DecimalField
ormongoengine.fields.FloatField
subclasses instance.
- Return type
- flask_mongoengine.db_fields._setup_strings_common_validators(options, obj)[source]
Extend
base_options
with common validators for string types.- Parameters
options (
dict
) – dict, usually fromWtfFieldMixin.wtf_generated_options
obj (
StringField
) – Anymongoengine.fields.StringField
subclass instance.
- Return type
flask_mongoengine.decorators module
Collection of project wide decorators.
flask_mongoengine.documents module
Extended version of mongoengine.document
.
- class flask_mongoengine.documents.BaseQuerySet(document, collection)[source]
Bases:
QuerySet
Extends
QuerySet
class with handly methods.- _abort_404(_message_404)[source]
Returns 404 error with message, if message provided.
- Parameters
_message_404 – Message for 404 comment
- first_or_404(_message_404=None)[source]
Same as
get_or_404()
, but usesfirst()
, notget()
.- Parameters
_message_404 – Message for 404 comment, not forwarded to
get()
- get_or_404(*args, _message_404=None, **kwargs)[source]
Get a document and raise a 404 Not Found error if it doesn’t exist.
- Parameters
_message_404 – Message for 404 comment, not forwarded to
get()
args – args list, silently forwarded to
get()
kwargs – keywords arguments, silently forwarded to
get()
- class flask_mongoengine.documents.Document(*args, **values)[source]
Bases:
WtfFormMixin
,Document
Abstract Document with QuerySet and WTForms extra helpers.
- __objects
- _cached_reference_fields = []
- _class_name = 'Document'
- _collection = None
- _db_field_map = {}
- _fields = {}
- _fields_ordered = ()
- _is_base_cls = False
- _is_document = True
- _meta = {'abstract': True, 'queryset_class': <class 'flask_mongoengine.documents.BaseQuerySet'>}
- _reverse_db_field_map = {}
- _subclasses = ('Document',)
- _superclasses = ()
- _types = ('Document',)
- class flask_mongoengine.documents.DynamicDocument(*args, **values)[source]
Bases:
WtfFormMixin
,DynamicDocument
Abstract DynamicDocument with QuerySet and WTForms extra helpers.
- _cached_reference_fields = []
- _class_name = 'DynamicDocument'
- _collection = None
- _db_field_map = {}
- _fields = {}
- _fields_ordered = ()
- _is_base_cls = False
- _is_document = True
- _meta = {'abstract': True, 'queryset_class': <class 'flask_mongoengine.documents.BaseQuerySet'>}
- _reverse_db_field_map = {}
- _subclasses = ('DynamicDocument',)
- _superclasses = ()
- _types = ('DynamicDocument',)
- class flask_mongoengine.documents.DynamicEmbeddedDocument(*args, **kwargs)[source]
Bases:
WtfFormMixin
,DynamicEmbeddedDocument
Abstract DynamicEmbeddedDocument document with extra WTForms helpers.
- _cached_reference_fields = []
- _class_name = 'DynamicEmbeddedDocument'
- _db_field_map = {}
- _fields = {}
- _fields_ordered = ()
- _instance
- _is_document = False
- _meta = {'abstract': True}
- _reverse_db_field_map = {}
- _subclasses = ('DynamicEmbeddedDocument',)
- _superclasses = ()
- _types = ('DynamicEmbeddedDocument',)
- class flask_mongoengine.documents.EmbeddedDocument(*args, **kwargs)[source]
Bases:
WtfFormMixin
,EmbeddedDocument
Abstract EmbeddedDocument document with extra WTForms helpers.
- _cached_reference_fields = []
- _class_name = 'EmbeddedDocument'
- _db_field_map = {}
- _fields = {}
- _fields_ordered = ()
- _instance
- _is_document = False
- _meta = {'abstract': True}
- _reverse_db_field_map = {}
- _subclasses = ('EmbeddedDocument',)
- _superclasses = ()
- _types = ('EmbeddedDocument',)
- class flask_mongoengine.documents.WtfFormMixin[source]
Bases:
object
Special mixin, for form generation functions.
- classmethod _get_fields_names(only, exclude)[source]
Filter fields names for further form generation.
- Parameters
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
.
- classmethod to_wtf_form(cls, base_class=<class 'flask_mongoengine.wtf.models.ModelForm'>, only=None, exclude=None, fields_kwargs=None)[source]
Generate WTForm from Document model.
- Parameters
base_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
.fields_kwargs (
Optional
[Dict
[str
,Dict
]]) –An optional dictionary of dictionaries, where field names mapping to keyword arguments used to construct each field object. Has the highest priority over all fields settings (made in Document field definition). Field options are directly passed to field generation, so must match WTForm Field keyword arguments. Support special field keyword option
wtf_field_class
, that can be used for complete field class replacement.Dictionary format example:
dictionary = { "field_name":{ "label":"new", "default": "new", "wtf_field_class": wtforms.fields.StringField } }
With such dictionary for field with name
field_name
wtforms.fields.StringField
will be called like:field_name = wtforms.fields.StringField(label="new", default="new")
- Return type
flask_mongoengine.json module
Flask application JSON extension functions.
- flask_mongoengine.json._convert_mongo_objects(obj)[source]
Convert objects, related to Mongo database to JSON.
- flask_mongoengine.json._make_encoder(superclass)[source]
Extend Flask JSON Encoder ‘default’ method with support of Mongo objects.
- flask_mongoengine.json._update_json_provider(superclass)[source]
Extend Flask Provider ‘default’ static method with support of Mongo objects.
- flask_mongoengine.json.override_json_encoder(app)[source]
A function to dynamically create a new MongoEngineJSONEncoder class based upon a custom base class. This function allows us to combine MongoEngine serialization with any changes to Flask’s JSONEncoder which a user may have made prior to calling init_app.
NOTE: This does not cover situations where users override an instance’s json_encoder after calling init_app.
flask_mongoengine.pagination module
Module responsible for custom pagination.
- class flask_mongoengine.pagination.ListFieldPagination(queryset, doc_id, field_name, page, per_page, total=None)[source]
Bases:
Pagination
- next(error_out=False)[source]
Returns a
Pagination
object for the next page.
- prev(error_out=False)[source]
Returns a
Pagination
object for the previous page.
- class flask_mongoengine.pagination.Pagination(iterable, page, per_page)[source]
Bases:
object
- property has_next
True if a next page exists.
- property has_prev
True if a previous page exists
- iter_pages(left_edge=2, left_current=2, right_current=5, right_edge=2)[source]
Iterates over the page numbers in the pagination. The four parameters control the thresholds how many numbers should be produced from the sides. Skipped page numbers are represented as None. This is how you could render such a pagination in the templates:
{% macro render_pagination(pagination, endpoint) %} <div class=pagination> {%- for page in pagination.iter_pages() %} {% if page %} {% if page != pagination.page %} <a href="{{ url_for(endpoint, page=page) }}">{{ page }}</a> {% else %} <strong>{{ page }}</strong> {% endif %} {% else %} <span class=ellipsis>…</span> {% endif %} {%- endfor %} </div> {% endmacro %}
- next(error_out=False)[source]
Returns a
Pagination
object for the next page.
- property next_num
Number of the next page
- property pages
The total number of pages
- prev(error_out=False)[source]
Returns a
Pagination
object for the previous page.
- property prev_num
Number of the previous page.
flask_mongoengine.panels module
Debug panel views and logic and related mongoDb event listeners.
- class flask_mongoengine.panels.RawQueryEvent(_event, _start_event, _is_query_pass)[source]
Bases:
object
Responsible for parsing monitoring events to web panel interface.
- Parameters
_event (
Union
[CommandSucceededEvent
,CommandFailedEvent
]) – Succeeded or Failed event object from pymongo monitoring._start_event (
CommandStartedEvent
) – Started event object from pymongo monitoring._is_query_pass (
bool
) – Boolean status of db query reported by pymongo monitoring.
- _event: Union[CommandSucceededEvent, CommandFailedEvent]
- _start_event: CommandStartedEvent
- property time
Query execution time.
- property size
Query object size.
- property database
Query database target.
- property collection
Query collection target.
- property command_name
Query db level operation/command name.
- property operation_id
MongoDb operation_id used to match ‘start’ and ‘final’ monitoring events.
- property server_command
Raw MongoDb command send to server.
- property server_response
Raw MongoDb response received from server.
- property request_status
Query execution status.
- class flask_mongoengine.panels.MongoCommandLogger[source]
Bases:
CommandListener
Receive point for
CommandListener
events.Count and parse incoming events for display in debug panel.
- flask_mongoengine.panels._maybe_patch_jinja_loader(jinja_env)[source]
Extend jinja_env loader with flask_mongoengine templates folder.
- class flask_mongoengine.panels.MongoDebugPanel(*args, **kwargs)[source]
Bases:
DebugPanel
Panel that shows information about MongoDB operations.
- config_error_message = 'Pymongo monitoring configuration error. mongo_command_logger should be registered before database connection.'
- name = 'MongoDB'
- has_content = True
- property is_properly_configured: bool
Checks that all required watchers registered before Flask application init.
- Return type
Debug toolbar in the bottom right corner.
- Return type
Count operations total time.
- Return type
flask_mongoengine.sessions module
- class flask_mongoengine.sessions.MongoEngineSession(initial=None, sid=None)[source]
Bases:
CallbackDict
,SessionMixin
- _abc_impl = <_abc._abc_data object>
- class flask_mongoengine.sessions.MongoEngineSessionInterface(db, collection='session')[source]
Bases:
SessionInterface
SessionInterface for mongoengine
- get_expiration_time(app, session)[source]
A helper method that returns an expiration date for the session or
None
if the session is linked to the browser session. The default implementation returns now + the permanent session lifetime configured on the application.- Return type
- open_session(app, request)[source]
This is called at the beginning of each request, after pushing the request context, before matching the URL.
This must return an object which implements a dictionary-like interface as well as the
SessionMixin
interface.This will return
None
to indicate that loading failed in some way that is not immediately an error. The request context will fall back to usingmake_null_session()
in this case.
Module contents
Note
Parent mongoengine project docs/docstrings has some formatting issues. If class/function/method link not clickable, search on provided parent documentation manually.