Base module API
This is the flask_mongoengine2 main modules API documentation.
flask_mongoengine2.connection module
Module responsible for connection setup.
- flask_mongoengine2.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_mongoengine2.connection._sanitize_settings(settings)[source]
Remove
MONGODB_prefix from dict values, to correct bypass to mongoengine.- Return type:
- flask_mongoengine2.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_mongoengine2.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_mongoengine2.db_fields module
flask_mongoengine2.decorators module
Collection of project wide decorators.
flask_mongoengine2.documents module
Module responsible for custom pagination.
- class flask_mongoengine2.pagination.ListFieldPagination(queryset, doc_id, field_name, page, per_page, total=None)[source]
Bases:
Pagination- next(error_out=False)[source]
Returns a
Paginationobject for the next page.
- prev(error_out=False)[source]
Returns a
Paginationobject for the previous page.
- class flask_mongoengine2.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
Paginationobject 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
Paginationobject for the previous page.
- property prev_num
Number of the previous page.
flask_mongoengine2.panels module
Debug panel views and logic and related mongoDb event listeners.
- class flask_mongoengine2.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_mongoengine2.panels.MongoCommandLogger[source]
Bases:
CommandListenerReceive point for
CommandListenerevents.Count and parse incoming events for display in debug panel.
- flask_mongoengine2.panels._maybe_patch_jinja_loader(jinja_env)[source]
Extend jinja_env loader with flask_mongoengine2 templates folder.
- class flask_mongoengine2.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 = '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_mongoengine2.sessions module
- class flask_mongoengine2.sessions.MongoEngineSession(initial=None, sid=None)[source]
Bases:
CallbackDict,SessionMixin- _abc_impl = <_abc._abc_data object>
- class flask_mongoengine2.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.