Files
Tablequizwiki/lib/middleware/current_user.py
Holger Sielaff 030d3c8059 initial
2024-07-03 21:41:03 +02:00

27 lines
498 B
Python

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