API Documentation¶
eve_mongoengine¶
This module implements Eve extension which enables Mongoengine models to be used as eve schema. If you use mongoengine in your application and simultaneously want to use eve, instead of writing schema again in cerberus format, you can use this extension, which takes your mongoengine models and auto-transforms it into creberus schema.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
- class eve_mongoengine.__init__.EveMongoengine(app)[source]¶
Bases: object
An extension to Eve which allows Mongoengine models to be registered as an Eve’s “domain”.
Acts as Flask extension and implements its ‘protocol’.
Usage:
from eve_mongoengine import EveMongoengine from eve import Eve app = Eve() ext = EveMongoengine(app) ext.add_model([MyModel, MySuperModel])
This class tries hard to be extendable and hackable as possible, every possible value is either a method param (for IoC-DI) or class attribute, which can be overwriten in subclass.
- add_model(models, lowercase=True, **settings)[source]¶
Creates Eve settings for mongoengine model classes.
Returns dict which has to be passed to the settings param in Eve’s constructor.
Parameters: - model – model or list of them (subclasses of mongoengine.Document).
- lowercase – if true, all class names will be taken lowercase as resource names. Default True.
- settings – any other keyword argument will be treated as param to settings dictionary.
- datalayer_class¶
Datalayer class - instance of this class is pushed to app.data attribute and Eve does it’s magic. See datalayer.MongoengineDataLayer for more info.
alias of MongoengineDataLayer
- default_item_methods = ['GET', 'PATCH', 'PUT', 'DELETE']¶
Default HTTP methods allowed to manipulate with items (single records). These are assigned to settings of every registered model, if not given others.
- default_resource_methods = ['GET', 'POST', 'DELETE']¶
Default HTTP methods allowed to manipulate with whole resources. These are assigned to settings of every registered model, if not given others.
- fix_model_class(model_cls)[source]¶
Internal method invoked during registering new model.
Adds necessary fields (updated and created) into model class to ensure Eve’s default functionality.
This is a helper for correct manipulation with mongoengine documents within Eve. Eve needs ‘updated’ and ‘created’ fields for it’s own purpose, but we cannot ensure that they are present in the model class. And even if they are, they may be of other field type or missbehave.
Parameters: model_cls – mongoengine’s model class (instance of subclass of mongoengine.Document) to be fixed up.
- init_app(app)[source]¶
Binds EveMongoengine extension to created eve application.
Under the hood it fixes all registered models and overwrites default eve’s datalayer eve.io.mongo.Mongo into eve_mongoengine.datalayer.MongoengineDataLayer.
This method implements flask extension interface: :param app: eve application object, instance of eve.Eve.
- schema_mapper_class¶
Mapper from mongoengine model into cerberus schema. This class may be subclassed in the future to support new mongoenigne’s fields.
alias of SchemaMapper
- settings_class¶
The class used as settings dictionary. Usually subclass of dict with tuned methods/behaviour.
alias of Settings
- validator_class¶
The class used as Eve validator, which is also one of Eve’s constructor params. In EveMongoengine, we need to overwrite it. If extending, assign only subclasses of EveMongoengineValidator.
alias of EveMongoengineValidator
eve_mongoengine.schema¶
Mapping mongoengine field types to cerberus schema.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
- class eve_mongoengine.schema.SchemaMapper[source]¶
Bases: object
Default mapper from mongoengine model classes into cerberus dict-like schema.
eve_mongoengine.validation¶
This module implements custom validator based on eve.io.mongo.validation, which is cerberus-validator extension.
The purpose of this module is to enable validation for special mongoengine fields.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
eve_mongoengine.struct¶
Datastructures for eve-mongoengine.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
eve_mongoengine.datalayer¶
This module implements eve’s data layer which uses mongoengine models instead of direct pymongo access.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
- class eve_mongoengine.datalayer.MongoengineDataLayer(ext)[source]¶
Bases: eve.io.mongo.mongo.Mongo
Data layer for eve-mongoengine extension.
Most of functionality is copied from eve.io.mongo.Mongo.
- find(resource, req, sub_resource_lookup)[source]¶
Seach for results and return list of them.
Parameters: - resource – name of requested resource as string.
- req – instance of eve.utils.ParsedRequest.
- sub_resource_lookup – sub-resource lookup from the endpoint url.
- json_encoder_class¶
alias of MongoengineJsonEncoder
- class eve_mongoengine.datalayer.MongoengineJsonEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None, use_decimal=True, namedtuple_as_object=True, tuple_as_array=True, bigint_as_string=False, item_sort_key=None, for_json=False, ignore_nan=False)[source]¶
Bases: eve.io.mongo.mongo.MongoJSONEncoder
Propretary JSON encoder to support special mongoengine’s special fields.