Skip to content

Commit

Permalink
refactor: compatibility the with only MIDDLEWARE
Browse files Browse the repository at this point in the history
This add the compatiblity for only he new django way of MIDDLEWARE.
  • Loading branch information
johanseto committed Feb 29, 2024
1 parent 6129772 commit 78d7582
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions eox_nelp/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""
from django.conf import settings
from django.http import parse_cookie
from django.utils.deprecation import MiddlewareMixin
from django.utils.translation import gettext_lazy as _

from eox_nelp.edxapp_wrapper.site_configuration import configuration_helpers
Expand Down Expand Up @@ -138,19 +137,24 @@ def handler(form_instance, form_desc, required=True):
return handler


class PreserveUserLanguageCookieMiddleware(MiddlewareMixin):
class PreserveUserLanguageCookieMiddleware:
"""This middleware ensure that in the COOKIES property the LANGUAGE_COOKIE_NAME
key has to be the cookie sent by the user and not other,
because it could be modified previously by other.
eg.
https://github.com/openedx/edx-platform/blob/open-release/palm.master/openedx/
core/djangoapps/lang_pref/middleware.py#L61-L62
"""
def process_request(self, request):
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
"""Process the request to change the language cookie based in original cookie value."""
original_user_language_cookie = parse_cookie(request.META.get("HTTP_COOKIE", "")).get(
settings.LANGUAGE_COOKIE_NAME
)

if original_user_language_cookie:
request.COOKIES[settings.LANGUAGE_COOKIE_NAME] = original_user_language_cookie

return self.get_response(request)

0 comments on commit 78d7582

Please sign in to comment.