initial
This commit is contained in:
26
lib/middleware/current_user.py
Normal file
26
lib/middleware/current_user.py
Normal 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
|
||||
Reference in New Issue
Block a user