Base Classes¶
-
class
nefertari_mongodb.documents.
BaseMixin
¶ Represents mixin class for models.
- Attributes:
- _auth_fields: String names of fields meant to be displayed to
- authenticated users.
- _public_fields: String names of fields meant to be displayed to
- non-authenticated users.
_hidden_fields: String names of fields meant to be hidden but editable. _nested_relationships: String names of reference/relationship fields
that should be included in JSON data of an object as full included documents. If reference/relationship field is not present in this list, this field’s value in JSON will be an object’s ID or list of IDs.- _nesting_depth: Depth of relationship field nesting in JSON.
- Defaults to 1(one) which makes only one level of relationship nested.
-
class
Q
(**query)¶ A simple query object, used in a query tree to build up more complex query structures.
-
BaseMixin.
__weakref__
¶ list of weak references to the object (if defined)
-
classmethod
BaseMixin.
_delete_many
(items, request=None)¶ Delete objects from :items:
-
BaseMixin.
_is_modified
()¶ Determine if instance is modified.
- For instance to be marked as ‘modified’, it should:
- Have PK field set (not newly created)
- Have changed fields
-
BaseMixin.
_to_python_fields
()¶ Call to_python on non-relation fields.
-
classmethod
BaseMixin.
_update_many
(items, params, request=None)¶ Update objects from :items:
If :items: is an instance of mongoengine.queryset.queryset.QuerySet items.update() is called. Otherwise update is performed per-object.
‘on_bulk_update’ is called explicitly, because mongoengine does not trigger any signals on QuerySet.update() call.
-
classmethod
BaseMixin.
autogenerate_for
(model, set_to)¶ Setup post_save event handler.
Event handler is registered for class :model: and creates a new instance of :cls: with a field :set_to: set to an instance on which the event occured.
The handler is set up as class method because mongoengine refuses to call signal handlers if they aren’t importable.
-
classmethod
BaseMixin.
expand_with
(with_cls, join_on=None, attr_name=None, params={}, with_params={})¶ Acts like “join” and inserts the with_cls objects in the result as “attr_name”.
-
classmethod
BaseMixin.
filter_fields
(params)¶ Filter out fields with invalid names.
-
classmethod
BaseMixin.
filter_objects
(objects, first=False, **params)¶ Perform query with :params: on instances sequence :objects:
- Arguments:
object: Sequence of :cls: instances on which query should be run. params: Query parameters to filter :objects:.
-
classmethod
BaseMixin.
get_collection
(**params)¶ Params may include ‘_limit’, ‘_page’, ‘_sort’, ‘_fields’. Returns paginated and sorted query set. Raises JHTTPBadRequest for bad values in params.
-
classmethod
BaseMixin.
get_es_mapping
(_depth=None, types_map=None)¶ Generate ES mapping from model schema.
-
classmethod
BaseMixin.
get_null_values
()¶ Get null values of :cls: fields.
Return pairs of (Model, istances) of relationship fields.
- Pair contains of two elements:
Model: Model class object(s) contained in field. instances: Model class instance(s) contained in field
Parameters: nested_only – Boolean, defaults to False. When True, return results only contain data for models on which current model and field are nested.
-
class
nefertari_mongodb.documents.
BaseDocument
(*args, **values)¶ -
__init__
(*args, **values)¶ Override init to filter out invalid fields from :values:.
Fields are filtered out to make mongoengine less strict when loading objects from database. :internal_fields: are the fields pop’ed from :values: before performing fields presence validation in the original mongoengine init code: https://github.com/MongoEngine/mongoengine/blob/v0.9.0/mongoengine/base/document.py#L41
PS. This issue is fixed in mongoengine master and not released after 0.9.0 yet. https://github.com/MongoEngine/mongoengine/blob/master/mongoengine/base/document.py#L75
-
clean
()¶ Clean fields which are instances of BaseFieldMixin
-
classmethod
get_field_params
(field_name)¶ Get init params of field named :field_name:.
-
run_backref_hooks
()¶ Runs post-save backref hooks.
Includes backref hooks which are used one time only to sync the backrefs.
-
save
(request=None, *arg, **kw)¶ Force insert document in creation so that unique constraits are respected. This makes each POST to a collection act as a ‘create’ operation (as opposed to an ‘update’ for example).
-
-
class
nefertari_mongodb.documents.
ESBaseDocument
(*args, **values)¶ Base for document classes which should be indexed by ES.