This commit is contained in:
Holger Sielaff
2024-07-03 21:41:03 +02:00
commit 030d3c8059
45 changed files with 2025 additions and 0 deletions

View File

View File

@@ -0,0 +1,26 @@
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