1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
netbox-community-netbox/netbox/extras/context_managers.py

26 lines
632 B
Python
Raw Normal View History

from contextlib import contextmanager
from netbox.context import current_request, webhooks_queue
2021-05-28 16:07:27 -04:00
from .webhooks import flush_webhooks
@contextmanager
def change_logging(request):
"""
Enable change logging by connecting the appropriate signals to their receivers before code is run, and
disconnecting them afterward.
:param request: WSGIRequest object with a unique `id` set
"""
current_request.set(request)
webhooks_queue.set([])
yield
2021-05-28 16:07:27 -04:00
# Flush queued webhooks to RQ
flush_webhooks(webhooks_queue.get())
# Clear context vars
current_request.set(None)
webhooks_queue.set([])