-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: having released_languages tenant and site aware DS-553 (#184)
* feat: having released_languages tenant and site aware * fix: add darklangmiddleware backend for test * fix: correct the format of the language_options in the proxy
- Loading branch information
Showing
8 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
eox_tenant/edxapp_wrapper/backends/dark_lang_middleware_o_test_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 @@ | ||
""" | ||
DarkLangMiddleware Backend for tests. | ||
""" | ||
from unittest.mock import MagicMock | ||
|
||
|
||
def get_dark_lang_middleware(): | ||
"""Backend to get the DarkLangMiddleware from openedx.""" | ||
return MagicMock() |
9 changes: 9 additions & 0 deletions
9
eox_tenant/edxapp_wrapper/backends/dark_lang_middleware_o_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 @@ | ||
""" | ||
DarkLangMiddleware Backend. | ||
""" | ||
from openedx.core.djangoapps.dark_lang.middleware import DarkLangMiddleware # pylint: disable=import-error | ||
|
||
|
||
def get_dark_lang_middleware(): | ||
"""Backend to get the DarkLangMiddleware from openedx.""" | ||
return DarkLangMiddleware |
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_dark_lang_middleware(*args, **kwargs): | ||
""" Get DarkLangMiddleware. """ | ||
backend_function = settings.DARK_LANG_MIDDLEWARE | ||
backend = import_module(backend_function) | ||
return backend.get_dark_lang_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
Site/Tenant aware languages filter. | ||
""" | ||
from collections import namedtuple | ||
|
||
from django.conf import settings | ||
|
||
Language = namedtuple('Language', 'code name') | ||
|
||
|
||
def tenant_languages(): | ||
"""Retrieve the list of released languages by tenant. | ||
Constructs a list of Language tuples by intersecting the | ||
list of valid language tuples with the list of released | ||
language codes. | ||
Returns: | ||
list of Language: Languages in which full translations are available. | ||
Example: | ||
>>> print released_languages() | ||
[Language(code='en', name=u'English'), Language(code='fr', name=u'Français')] | ||
""" | ||
released_languages = getattr(settings, "released_languages", "") | ||
released_language_codes = [lang.lower().strip() for lang in released_languages.split(',')] | ||
default_language_code = settings.LANGUAGE_CODE | ||
|
||
if default_language_code not in released_language_codes: | ||
released_language_codes.append(default_language_code) | ||
|
||
released_language_codes.sort() | ||
|
||
# Intersect the list of valid language tuples with the list | ||
# of released language codes | ||
return [ | ||
Language(language_info[0], language_info[1]) | ||
for language_info in settings.LANGUAGES | ||
if language_info[0] in released_language_codes | ||
] |
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