From 78d75821ad5abf6746957e11d260a75148dccc1b Mon Sep 17 00:00:00 2001 From: Johan Castiblanco Date: Thu, 29 Feb 2024 15:33:42 -0500 Subject: [PATCH] refactor: compatibility the with only MIDDLEWARE This add the compatiblity for only he new django way of MIDDLEWARE. --- eox_nelp/middleware.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/eox_nelp/middleware.py b/eox_nelp/middleware.py index f336ac04..7ffafa4d 100644 --- a/eox_nelp/middleware.py +++ b/eox_nelp/middleware.py @@ -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 @@ -138,7 +137,7 @@ 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. @@ -146,7 +145,10 @@ class PreserveUserLanguageCookieMiddleware(MiddlewareMixin): 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 @@ -154,3 +156,5 @@ def process_request(self, request): if original_user_language_cookie: request.COOKIES[settings.LANGUAGE_COOKIE_NAME] = original_user_language_cookie + + return self.get_response(request)