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
55257269
Commit
55257269
authored
Feb 11, 2014
by
Julia Hansbrough
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added middleware for handling language changes
parent
7d81a510
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
cms/envs/common.py
+1
-0
common/djangoapps/user_api/middleware.py
+27
-0
No files found.
cms/envs/common.py
View file @
55257269
...
...
@@ -462,6 +462,7 @@ INSTALLED_APPS = (
# User preferences
'user_api'
,
'django_openid_auth'
,
)
...
...
common/djangoapps/user_api/middleware.py
0 → 100644
View file @
55257269
"""
Middleware for UserPreferences
"""
from
django.utils.translation.trans_real
import
parse_accept_lang_header
from
user_api.models
import
UserPreference
,
LANGUAGE_KEY
class
UserPreferenceMiddleware
(
object
):
"""
Middleware for user preferences.
Ensures that, once set, a user's preferences are reflected in the page
whenever they are logged in.
"""
def
process_request
(
self
,
request
):
"""
If a user's UserPreference contains a language preference,
stick that preference in the session.
"""
query
=
UserPreference
.
objects
.
filter
(
user
=
request
.
user
,
key
=
LANGUAGE_KEY
)
if
query
.
exists
():
# there should only be one result for query
request
.
session
[
'django_language'
]
=
query
[
0
]
.
value
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