17 lines
664 B
Python
17 lines
664 B
Python
from django.utils.deprecation import MiddlewareMixin
|
|
|
|
|
|
class CookieMiddleware(MiddlewareMixin):
|
|
"""Middleware to handle cookies"""
|
|
|
|
def process_request(self, request):
|
|
# Check locale in cookies if locale not exists in DB return 406
|
|
# if 'locale' not in request.COOKIES or \
|
|
# not Language.objects.by_locale(request.COOKIES.get('locale'))\
|
|
# .exists():
|
|
# return HttpResponse(status=status.HTTP_406_NOT_ACCEPTABLE)
|
|
#
|
|
# Add to request attrs from cookie
|
|
for cookie in request.COOKIES:
|
|
setattr(request, cookie, request.COOKIES[cookie])
|