Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
55257269
Commit
55257269
authored
11 years ago
by
Julia Hansbrough
Browse files
Options
Downloads
Patches
Plain Diff
Added middleware for handling language changes
parent
7d81a510
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cms/envs/common.py
+1
-0
1 addition, 0 deletions
cms/envs/common.py
common/djangoapps/user_api/middleware.py
+27
-0
27 additions, 0 deletions
common/djangoapps/user_api/middleware.py
with
28 additions
and
0 deletions
cms/envs/common.py
+
1
−
0
View file @
55257269
...
...
@@ -462,6 +462,7 @@ INSTALLED_APPS = (
# User preferences
'
user_api
'
,
'
django_openid_auth
'
,
)
...
...
This diff is collapsed.
Click to expand it.
common/djangoapps/user_api/middleware.py
0 → 100644
+
27
−
0
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment