-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user lang cookie preference (#265)
* feat: add user lang cookie preference * test: add UserLanguagePreferenceMiddlewere tests
- Loading branch information
Showing
8 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
eox_core/edxapp_wrapper/backends/lang_pref_middleware_p_v1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
LanguagePreferenceMiddleware Backend. | ||
""" | ||
from openedx.core.djangoapps.lang_pref.middleware import LanguagePreferenceMiddleware # pylint: disable=import-error | ||
|
||
|
||
def get_language_preference_middleware(): | ||
"""Backend to get the LanguagePreferenceMiddleware from openedx.""" | ||
return LanguagePreferenceMiddleware |
18 changes: 18 additions & 0 deletions
18
eox_core/edxapp_wrapper/backends/lang_pref_middleware_p_v1_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
LanguagePreferenceMiddleware Backend. | ||
""" | ||
|
||
|
||
def get_language_preference_middleware(): | ||
"""Backend to get the LanguagePreferenceMiddleware from openedx.""" | ||
class LanguagePreferenceMiddleware: | ||
"""LanguagePreferenceMiddleware Backend Mock.""" | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
# Simulate the behavior of LanguagePreferenceMiddleware | ||
# For example, set a language preference in the request | ||
request.LANGUAGE_CODE = 'en' | ||
return self.get_response(request) | ||
return LanguagePreferenceMiddleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
""" Backend abstraction. """ | ||
from importlib import import_module | ||
|
||
from django.conf import settings | ||
|
||
|
||
def get_language_preference_middleware(*args, **kwargs): | ||
""" Get LanguagePreferenceMiddleware. """ | ||
backend_function = settings.EOX_CORE_LANG_PREF_BACKEND | ||
backend = import_module(backend_function) | ||
return backend.get_language_preference_middleware(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters