PyInventory/inventory/middlewares.py

22 wiersze
530 B
Python
Czysty Zwykły widok Historia

2020-10-24 15:15:05 +00:00
from inventory.request_dict import clear_request_dict, get_request_dict
class RequestDictMiddleware:
"""
2020-12-20 17:45:17 +00:00
Make the "current user" information available everywhere via threading.local()
2020-10-24 15:15:05 +00:00
Access e.g.:
user = get_request_dict()['user']
"""
2020-10-24 17:43:54 +00:00
2020-10-24 15:15:05 +00:00
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
get_request_dict().update(user=request.user)
response = self.get_response(request)
clear_request_dict()
return response