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_SETTINGSkey, 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,BinaryFieldExtends
mongoengine.fields.BinaryFieldwith 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,BooleanFieldExtends
mongoengine.fields.BooleanFieldwith 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,CachedReferenceFieldExtends
mongoengine.fields.CachedReferenceFieldwith 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,ComplexDateTimeFieldExtends
mongoengine.fields.ComplexDateTimeFieldwith 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.DateTimeLocalFieldwith milliseconds accuracy. Direct microseconds not supported by browsers for this type of field. If exact microseconds support required, please usewtforms.fields.DateTimeFieldwith 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,DateFieldExtends
mongoengine.fields.DateFieldwith 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,DateTimeFieldExtends
mongoengine.fields.DateTimeFieldwith 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,DecimalFieldExtends
mongoengine.fields.DecimalFieldwith 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.
- 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,DictFieldExtends
mongoengine.fields.DictFieldwith 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,DynamicFieldExtends
mongoengine.fields.DynamicFieldwith 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,EmailFieldExtends
mongoengine.fields.EmailFieldwith 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
NoneStringFieldtoflask_mongoengine.wtf.fields.MongoEmailField- DEFAULT_WTF_FIELD
alias of
MongoEmailField
- property wtf_generated_options: dict
Extend form validators with
wtforms.validators.Email
- 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,EmbeddedDocumentFieldExtends
mongoengine.fields.EmbeddedDocumentFieldwith 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,EmbeddedDocumentListFieldExtends
mongoengine.fields.EmbeddedDocumentListFieldwith 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,EnumFieldExtends
mongoengine.fields.EnumFieldwith 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,FileFieldExtends
mongoengine.fields.FileFieldwith 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,FloatFieldExtends
mongoengine.fields.FloatFieldwith 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.FloatFieldtoflask_mongoengine.wtf.fields.MongoFloatFieldwith ‘numbers’ input type.- DEFAULT_WTF_FIELD
alias of
MongoFloatField
- property wtf_generated_options: dict
Extend form validators with
wtforms.validators.NumberRange.
- 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,GenericEmbeddedDocumentFieldExtends
mongoengine.fields.GenericEmbeddedDocumentFieldwith 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,GenericLazyReferenceFieldExtends
mongoengine.fields.GenericLazyReferenceFieldwith 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,GenericReferenceFieldExtends
mongoengine.fields.GenericReferenceFieldwith 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,GeoJsonBaseFieldExtends
mongoengine.fields.GeoJsonBaseFieldwith 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,GeoPointFieldExtends
mongoengine.fields.GeoPointFieldwith 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,ImageFieldExtends
mongoengine.fields.ImageFieldwith 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,IntFieldExtends
mongoengine.fields.IntFieldwith 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.
- 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,LazyReferenceFieldExtends
mongoengine.fields.LazyReferenceFieldwith 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,LineStringFieldExtends
mongoengine.fields.LineStringFieldwith 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,ListFieldExtends
mongoengine.fields.ListFieldwith 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,LongFieldExtends
mongoengine.fields.LongFieldwith 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,MapFieldExtends
mongoengine.fields.MapFieldwith 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,MultiLineStringFieldExtends
mongoengine.fields.MultiLineStringFieldwith 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,MultiPointFieldExtends
mongoengine.fields.MultiPointFieldwith 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,MultiPolygonFieldExtends
mongoengine.fields.MultiPolygonFieldwith 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,ObjectIdFieldExtends
mongoengine.fields.ObjectIdFieldwith 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,PointFieldExtends
mongoengine.fields.PointFieldwith 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,PolygonFieldExtends
mongoengine.fields.PolygonFieldwith 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,ReferenceFieldExtends
mongoengine.fields.ReferenceFieldwith 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,SequenceFieldExtends
mongoengine.fields.SequenceFieldwith 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,SortedListFieldExtends
mongoengine.fields.SortedListFieldwith 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,StringFieldExtends
mongoengine.fields.StringFieldwith 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
NoneStringFieldtoflask_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 useMongoPasswordFieldfor field generation. In case ofpasswordandwtf_field_classboth set, thenwtf_field_classwill be used.textarea (
bool) – DEPRECATED: Force to useMongoTextAreaFieldfor field generation. In case oftextareaandwtf_field_classboth set, thenwtf_field_classwill 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.Fieldthat can be used for form field generation. Takes precedence overDEFAULT_WTF_FIELDandDEFAULT_WTF_CHOICES_FIELDwtf_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_COERCEfor 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.
- property wtf_generated_options: dict
Extend form validators with
wtforms.validators.Regexpandwtforms.validators.Length.
- 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,URLFieldExtends
mongoengine.fields.URLFieldwith 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
NoneStringFieldtoMongoURLFieldChanged in version 2.0.0: Now appends
Regexpand 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
- 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,UUIDFieldExtends
mongoengine.fields.UUIDFieldwith 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:
objectExtension 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.Fieldthat can be used for form field generation. Takes precedence overDEFAULT_WTF_FIELDandDEFAULT_WTF_CHOICES_FIELDwtf_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_COERCEfor 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_kwargsparameter.
- property wtf_field_options: dict
Final WTForm Field options that will be applied as
wtf_field_classkwargs.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
- flask_mongoengine.db_fields._setup_numbers_common_validators(options, obj)[source]
Extend
base_optionswith common validators for number types.- Parameters:
options (
dict) – dict, usually fromWtfFieldMixin.wtf_generated_optionsobj (
Union[IntField,DecimalField,FloatField]) – Anymongoengine.fields.IntFieldormongoengine.fields.DecimalFieldormongoengine.fields.FloatFieldsubclasses instance.
- Return type:
- flask_mongoengine.db_fields._setup_strings_common_validators(options, obj)[source]
Extend
base_optionswith common validators for string types.- Parameters:
options (
dict) – dict, usually fromWtfFieldMixin.wtf_generated_optionsobj (
StringField) – Anymongoengine.fields.StringFieldsubclass 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:
QuerySetExtends
QuerySetclass 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()
- paginate(page, per_page, first_page_index=1)[source]
Paginate the QuerySet with a certain number of docs per page and return docs for a given page.
- class flask_mongoengine.documents.Document(*args, **values)[source]
Bases:
WtfFormMixin,DocumentAbstract 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,DynamicDocumentAbstract 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,DynamicEmbeddedDocumentAbstract 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,EmbeddedDocumentAbstract 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:
objectSpecial 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 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.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_namewtforms.fields.StringFieldwill 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
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:
objectResponsible 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:
CommandListenerReceive point for
CommandListenerevents.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:
DebugPanelPanel that shows information about MongoDB operations.
- config_error_message = 'Pymongo monitoring configuration error. mongo_command_logger should be registered before database connection.'
- name: str = 'MongoDB'
- has_content = True
- property is_properly_configured: bool
Checks that all required watchers registered before Flask application init.
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:
SessionInterfaceSessionInterface for mongoengine
- get_expiration_time(app, session)[source]
A helper method that returns an expiration date for the session or
Noneif 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
SessionMixininterface.This will return
Noneto 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.