Files

27 lines
498 B
Python
Raw Permalink Normal View History

2024-07-03 21:41:03 +02:00
from threading import local
from django.utils.deprecation import MiddlewareMixin
_user = local()
_request = local()
class CurrentUserMiddleware(MiddlewareMixin):
def process_request(self, request):
_user.value = request.user
_request.value = request
def get_current_user():
try:
return _user.value
except AttributeError:
return None
def get_current_request():
try:
return _request.value
except AttributeError:
return None