Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
f8b050a5
Commit
f8b050a5
authored
Apr 24, 2017
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Put LANGUAGE_COOKIE into settings
parent
4cc23bc6
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
19 additions
and
13 deletions
+19
-13
cms/envs/aws.py
+2
-0
cms/envs/common.py
+2
-0
lms/envs/aws.py
+2
-0
lms/envs/common.py
+2
-0
openedx/core/djangoapps/lang_pref/__init__.py
+0
-2
openedx/core/djangoapps/lang_pref/middleware.py
+4
-4
openedx/core/djangoapps/lang_pref/tests/test_middleware.py
+5
-5
openedx/core/djangoapps/lang_pref/views.py
+2
-2
No files found.
cms/envs/aws.py
View file @
f8b050a5
...
...
@@ -221,6 +221,8 @@ GIT_REPO_EXPORT_DIR = ENV_TOKENS.get('GIT_REPO_EXPORT_DIR', '/edx/var/edxapp/exp
# Translation overrides
LANGUAGES
=
ENV_TOKENS
.
get
(
'LANGUAGES'
,
LANGUAGES
)
LANGUAGE_CODE
=
ENV_TOKENS
.
get
(
'LANGUAGE_CODE'
,
LANGUAGE_CODE
)
LANGUAGE_COOKIE
=
ENV_TOKENS
.
get
(
'LANGUAGE_COOKIE'
,
LANGUAGE_COOKIE
)
USE_I18N
=
ENV_TOKENS
.
get
(
'USE_I18N'
,
USE_I18N
)
ENV_FEATURES
=
ENV_TOKENS
.
get
(
'FEATURES'
,
{})
...
...
cms/envs/common.py
View file @
f8b050a5
...
...
@@ -547,6 +547,8 @@ TIME_ZONE = 'America/New_York' # http://en.wikipedia.org/wiki/List_of_tz_zones_
LANGUAGE_CODE
=
'en'
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGES_BIDI
=
lms
.
envs
.
common
.
LANGUAGES_BIDI
LANGUAGE_COOKIE
=
lms
.
envs
.
common
.
LANGUAGE_COOKIE
LANGUAGES
=
lms
.
envs
.
common
.
LANGUAGES
LANGUAGE_DICT
=
dict
(
LANGUAGES
)
...
...
lms/envs/aws.py
View file @
f8b050a5
...
...
@@ -314,6 +314,8 @@ TIME_ZONE = ENV_TOKENS.get('TIME_ZONE', TIME_ZONE)
LANGUAGES
=
ENV_TOKENS
.
get
(
'LANGUAGES'
,
LANGUAGES
)
LANGUAGE_DICT
=
dict
(
LANGUAGES
)
LANGUAGE_CODE
=
ENV_TOKENS
.
get
(
'LANGUAGE_CODE'
,
LANGUAGE_CODE
)
LANGUAGE_COOKIE
=
ENV_TOKENS
.
get
(
'LANGUAGE_COOKIE'
,
LANGUAGE_COOKIE
)
USE_I18N
=
ENV_TOKENS
.
get
(
'USE_I18N'
,
USE_I18N
)
# Additional installed apps
...
...
lms/envs/common.py
View file @
f8b050a5
...
...
@@ -860,6 +860,8 @@ LANGUAGE_CODE = 'en' # http://www.i18nguy.com/unicode/language-identifiers.html
# these languages display right to left
LANGUAGES_BIDI
=
(
"he"
,
"ar"
,
"fa"
,
"ur"
,
"fa-ir"
,
"rtl"
)
LANGUAGE_COOKIE
=
"openedx-language-preference"
# Sourced from http://www.localeplanet.com/icu/ and wikipedia
LANGUAGES
=
(
(
'en'
,
u'English'
),
...
...
openedx/core/djangoapps/lang_pref/__init__.py
View file @
f8b050a5
...
...
@@ -5,8 +5,6 @@ Useful information for setting the language preference
# this is the UserPreference key for the user's preferred language
LANGUAGE_KEY
=
'pref-lang'
LANGUAGE_COOKIE
=
'edx-language-preference'
LANGUAGE_HEADER
=
'HTTP_ACCEPT_LANGUAGE'
COOKIE_DURATION
=
14
*
24
*
60
*
60
# 14 days in seconds
openedx/core/djangoapps/lang_pref/middleware.py
View file @
f8b050a5
...
...
@@ -7,7 +7,7 @@ from django.utils.translation import LANGUAGE_SESSION_KEY
from
django.utils.translation.trans_real
import
parse_accept_lang_header
from
openedx.core.djangoapps.lang_pref
import
(
LANGUAGE_KEY
,
LANGUAGE_
COOKIE
,
LANGUAGE_
HEADER
,
COOKIE_DURATION
LANGUAGE_KEY
,
LANGUAGE_HEADER
,
COOKIE_DURATION
)
from
openedx.core.djangoapps.user_api.preferences.api
import
(
get_user_preference
,
delete_user_preference
,
set_user_preference
...
...
@@ -28,7 +28,7 @@ class LanguagePreferenceMiddleware(object):
If a user's UserPreference contains a language preference, use the user's preference.
Save the current language preference cookie as the user's preferred language.
"""
cookie_lang
=
request
.
COOKIES
.
get
(
LANGUAGE_COOKIE
,
None
)
cookie_lang
=
request
.
COOKIES
.
get
(
settings
.
LANGUAGE_COOKIE
,
None
)
if
cookie_lang
:
if
request
.
user
.
is_authenticated
():
set_user_preference
(
request
.
user
,
LANGUAGE_KEY
,
cookie_lang
)
...
...
@@ -57,14 +57,14 @@ class LanguagePreferenceMiddleware(object):
# Set it in the LANGUAGE_COOKIE
if
user_pref
:
response
.
set_cookie
(
LANGUAGE_COOKIE
,
settings
.
LANGUAGE_COOKIE
,
value
=
user_pref
,
domain
=
settings
.
SESSION_COOKIE_DOMAIN
,
max_age
=
COOKIE_DURATION
,
)
else
:
response
.
delete_cookie
(
LANGUAGE_COOKIE
,
settings
.
LANGUAGE_COOKIE
,
domain
=
settings
.
SESSION_COOKIE_DOMAIN
)
...
...
openedx/core/djangoapps/lang_pref/tests/test_middleware.py
View file @
f8b050a5
...
...
@@ -14,7 +14,7 @@ from django.contrib.sessions.middleware import SessionMiddleware
from
django.utils.translation
import
LANGUAGE_SESSION_KEY
from
django.utils.translation.trans_real
import
parse_accept_lang_header
from
openedx.core.djangoapps.lang_pref
import
LANGUAGE_KEY
,
LANGUAGE_COOKIE
,
COOKIE_DURATION
from
openedx.core.djangoapps.lang_pref
import
LANGUAGE_KEY
,
COOKIE_DURATION
from
openedx.core.djangoapps.lang_pref.middleware
import
LanguagePreferenceMiddleware
from
openedx.core.djangoapps.user_api.preferences.api
import
set_user_preference
,
get_user_preference
,
delete_user_preference
from
student.tests.factories
import
UserFactory
...
...
@@ -65,14 +65,14 @@ class TestUserPreferenceMiddleware(TestCase):
if
lang_pref_out
:
response
.
set_cookie
.
assert_called_with
(
LANGUAGE_COOKIE
,
settings
.
LANGUAGE_COOKIE
,
value
=
lang_pref_out
,
domain
=
settings
.
SESSION_COOKIE_DOMAIN
,
max_age
=
COOKIE_DURATION
,
)
else
:
response
.
delete_cookie
.
assert_called_with
(
LANGUAGE_COOKIE
,
settings
.
LANGUAGE_COOKIE
,
domain
=
settings
.
SESSION_COOKIE_DOMAIN
,
)
...
...
@@ -85,7 +85,7 @@ class TestUserPreferenceMiddleware(TestCase):
@ddt.unpack
@mock.patch
(
'openedx.core.djangoapps.lang_pref.middleware.set_user_preference'
)
def
test_preference_cookie_changes_setting
(
self
,
lang_cookie
,
lang_pref_in
,
mock_set_user_preference
):
self
.
request
.
COOKIES
[
LANGUAGE_COOKIE
]
=
lang_cookie
self
.
request
.
COOKIES
[
settings
.
LANGUAGE_COOKIE
]
=
lang_cookie
if
lang_pref_in
:
set_user_preference
(
self
.
user
,
LANGUAGE_KEY
,
lang_pref_in
)
...
...
@@ -120,7 +120,7 @@ class TestUserPreferenceMiddleware(TestCase):
if
not
logged_in
:
self
.
request
.
user
=
self
.
anonymous_user
if
lang_cookie
:
self
.
request
.
COOKIES
[
LANGUAGE_COOKIE
]
=
lang_cookie
self
.
request
.
COOKIES
[
settings
.
LANGUAGE_COOKIE
]
=
lang_cookie
if
lang_session
:
self
.
request
.
session
[
LANGUAGE_SESSION_KEY
]
=
lang_session
if
accept_lang_in
:
...
...
openedx/core/djangoapps/lang_pref/views.py
View file @
f8b050a5
...
...
@@ -9,7 +9,7 @@ from django.http import HttpResponse
from
django.views.decorators.csrf
import
ensure_csrf_cookie
from
django.utils.translation
import
LANGUAGE_SESSION_KEY
from
openedx.core.djangoapps.lang_pref
import
LANGUAGE_KEY
,
LANGUAGE_COOKIE
,
COOKIE_DURATION
from
openedx.core.djangoapps.lang_pref
import
LANGUAGE_KEY
,
COOKIE_DURATION
@ensure_csrf_cookie
...
...
@@ -24,7 +24,7 @@ def update_session_language(request):
if
request
.
session
.
get
(
LANGUAGE_SESSION_KEY
,
None
)
!=
language
:
request
.
session
[
LANGUAGE_SESSION_KEY
]
=
unicode
(
language
)
response
.
set_cookie
(
LANGUAGE_COOKIE
,
settings
.
LANGUAGE_COOKIE
,
language
,
domain
=
settings
.
SESSION_COOKIE_DOMAIN
,
max_age
=
COOKIE_DURATION
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment