nautobot.apps.change_logging
¶
Classes and utilities related to Nautobot change logging.
nautobot.apps.change_logging.ChangeContext
¶
ChangeContext is used to describe a single transaction that may be related to one or more object changes. A unique id can be provided, otherwise one will be generated to relate any changes to this transaction. Convenience classes are provided for each context.
:param user: User object :param request: WSGIRequest object to retrieve user from django rest framework after authentication is performed :param context: Context of the transaction, must match a choice in nautobot.extras.choices.ObjectChangeEventContextChoices :param context_detail: Optional extra details about the transaction (ex: the plugin name that initiated the change) :param change_id: Optional uuid object to uniquely identify the transaction. One will be generated if not supplied
Source code in nautobot/extras/context_managers.py
nautobot.apps.change_logging.JobChangeContext
¶
Bases: ChangeContext
ChangeContext for changes made by jobs
Source code in nautobot/extras/context_managers.py
nautobot.apps.change_logging.JobHookChangeContext
¶
Bases: ChangeContext
ChangeContext for changes made by job hooks
Source code in nautobot/extras/context_managers.py
nautobot.apps.change_logging.ORMChangeContext
¶
Bases: ChangeContext
ChangeContext for changes made with web_request_context context manager
Source code in nautobot/extras/context_managers.py
nautobot.apps.change_logging.WebChangeContext
¶
Bases: ChangeContext
ChangeContext for changes made through the web interface
Source code in nautobot/extras/context_managers.py
nautobot.apps.change_logging.change_logging(change_context)
¶
Enable change logging by connecting the appropriate signals to their receivers before code is run, and disconnecting them afterward.
:param change_context: ChangeContext instance
Source code in nautobot/extras/context_managers.py
nautobot.apps.change_logging.web_request_context(user, context_detail='', change_id=None)
¶
Emulate the context of an HTTP request, which provides functions like change logging and webhook processing in response to data changes. This context manager is for use with low level utility tooling, such as the 'nautobot-server nbshell' management command.
By default, when working with the Django ORM, neither change logging nor webhook processing occur unless manually invoked and this context manager handles those functions. A valid User object must be provided.
Example usage:
from nautobot.extras.context_managers import web_request_context user = User.objects.get(username="admin") with web_request_context(user, context_detail="manual-fix"): ... lt = Location.objects.get(name="Root") ... lax = Location(name="LAX", location_type=lt) ... lax.validated_save()
:param user: User object :param context_detail: Optional extra details about the transaction (ex: the plugin name that initiated the change) :param change_id: Optional uuid object to uniquely identify the transaction. One will be generated if not supplied