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
91f1923d
Commit
91f1923d
authored
Jun 08, 2017
by
Sofiya Semenova
Committed by
GitHub
Jun 08, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15266 from edx/ssemenova/EDUCATOR-367
ED-367 log in production logging when it shouldn't be
parents
c3a7088a
6acc6fde
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
19 deletions
+12
-19
common/djangoapps/request_cache/__init__.py
+1
-6
openedx/core/djangoapps/user_api/models.py
+9
-0
openedx/core/djangoapps/user_api/preferences/api.py
+1
-12
openedx/core/djangoapps/user_api/serializers.py
+1
-1
No files found.
common/djangoapps/request_cache/__init__.py
View file @
91f1923d
...
...
@@ -68,16 +68,11 @@ def get_request_or_stub():
request that can be used to build an absolute URI.
This is useful in cases where we need to pass in a request object
but don't have an active request (for example, in test
case
s).
but don't have an active request (for example, in test
s, celery tasks, and XBlock
s).
"""
request
=
crum
.
get_current_request
()
if
request
is
None
:
log
.
warning
(
"Could not retrieve the current request. "
"A stub request will be created instead using settings.SITE_NAME. "
"This should be used *only* in test cases, never in production!"
)
# The settings SITE_NAME may contain a port number, so we need to
# parse the full URL.
...
...
openedx/core/djangoapps/user_api/models.py
View file @
91f1923d
...
...
@@ -29,6 +29,15 @@ class UserPreference(models.Model):
class
Meta
(
object
):
unique_together
=
(
"user"
,
"key"
)
@staticmethod
def
get_all_preferences
(
user
):
"""
Gets all preferences for a given user
Returns: Set of (preference type, value) pairs for each of the user's preferences
"""
return
dict
([(
pref
.
key
,
pref
.
value
)
for
pref
in
user
.
preferences
.
all
()])
@classmethod
def
get_value
(
cls
,
user
,
preference_key
,
default
=
None
):
"""Gets the user preference value for a given key.
...
...
openedx/core/djangoapps/user_api/preferences/api.py
View file @
91f1923d
...
...
@@ -72,18 +72,7 @@ def get_user_preferences(requesting_user, username=None):
UserAPIInternalError: the operation failed due to an unexpected error.
"""
existing_user
=
_get_authorized_user
(
requesting_user
,
username
,
allow_staff
=
True
)
# Django Rest Framework V3 uses the current request to version
# hyperlinked URLS, so we need to retrieve the request and pass
# it in the serializer's context (otherwise we get an AssertionError).
# We're retrieving the request from the cache rather than passing it in
# as an argument because this is an implementation detail of how we're
# serializing data, which we want to encapsulate in the API call.
context
=
{
"request"
:
get_request_or_stub
()
}
user_serializer
=
UserSerializer
(
existing_user
,
context
=
context
)
return
user_serializer
.
data
[
"preferences"
]
return
UserPreference
.
get_all_preferences
(
existing_user
)
@intercept_errors
(
UserAPIInternalError
,
ignore_errors
=
[
UserAPIRequestError
])
...
...
openedx/core/djangoapps/user_api/serializers.py
View file @
91f1923d
...
...
@@ -28,7 +28,7 @@ class UserSerializer(serializers.HyperlinkedModelSerializer):
"""
Returns the set of preferences as a dict for the specified user
"""
return
dict
([(
pref
.
key
,
pref
.
value
)
for
pref
in
user
.
preferences
.
all
()]
)
return
UserPreference
.
get_all_preferences
(
user
)
class
Meta
(
object
):
model
=
User
...
...
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