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
2abe3f7e
Commit
2abe3f7e
authored
Sep 13, 2016
by
Robert Raposa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reuse already retrieved user object.
parent
726a5911
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
10 deletions
+19
-10
lms/djangoapps/discussion/views.py
+19
-10
No files found.
lms/djangoapps/discussion/views.py
View file @
2abe3f7e
...
...
@@ -63,10 +63,22 @@ def make_course_settings(course, user):
@newrelic.agent.function_trace
()
def
get_threads
(
request
,
course
,
discussion_id
=
None
,
per_page
=
THREADS_PER_PAGE
):
def
get_threads
(
request
,
course
,
user_info
,
discussion_id
=
None
,
per_page
=
THREADS_PER_PAGE
):
"""
This may raise an appropriate subclass of cc.utils.CommentClientError
if something goes wrong, or ValueError if the group_id is invalid.
Arguments:
request: The user request.
course: The course object.
user_info: The comment client User object as a dict.
discussion_id: Optional discussion id/commentable id for context.
per_page: Optional number of threads per page.
Returns:
A tuple of the threads and the query parameters used for the search.
:return:
"""
default_query_params
=
{
'page'
:
1
,
...
...
@@ -90,12 +102,9 @@ def get_threads(request, course, discussion_id=None, per_page=THREADS_PER_PAGE):
if
not
request
.
GET
.
get
(
'sort_key'
):
# If the user did not select a sort key, use their last used sort key
cc_user
=
cc
.
User
.
from_django_user
(
request
.
user
)
cc_user
.
retrieve
()
# TODO: After the comment service is updated this can just be
# user.default_sort_key because the service returns the default value
default_query_params
[
'sort_key'
]
=
cc_user
.
get
(
'default_sort_key'
)
or
default_query_params
[
'sort_key'
]
else
:
default_query_params
[
'sort_key'
]
=
user_info
.
get
(
'default_sort_key'
)
or
default_query_params
[
'sort_key'
]
elif
request
.
GET
.
get
(
'sort_key'
)
!=
user_info
.
get
(
'default_sort_key'
):
# If the user clicked a sort key, update their default sort key
cc_user
=
cc
.
User
.
from_django_user
(
request
.
user
)
cc_user
.
default_sort_key
=
request
.
GET
.
get
(
'sort_key'
)
...
...
@@ -175,7 +184,7 @@ def inline_discussion(request, course_key, discussion_id):
user_info
=
cc_user
.
to_dict
()
try
:
threads
,
query_params
=
get_threads
(
request
,
course
,
discussion_id
,
per_page
=
INLINE_THREADS_PER_PAGE
)
threads
,
query_params
=
get_threads
(
request
,
course
,
user_info
,
discussion_id
,
per_page
=
INLINE_THREADS_PER_PAGE
)
except
ValueError
:
return
HttpResponseBadRequest
(
"Invalid group_id"
)
...
...
@@ -212,7 +221,7 @@ def forum_form_discussion(request, course_key):
user_info
=
user
.
to_dict
()
try
:
unsafethreads
,
query_params
=
get_threads
(
request
,
course
)
# This might process a search query
unsafethreads
,
query_params
=
get_threads
(
request
,
course
,
user_info
)
# This might process a search query
is_staff
=
has_permission
(
request
.
user
,
'openclose_thread'
,
course
.
id
)
threads
=
[
utils
.
prepare_content
(
thread
,
course_key
,
is_staff
)
for
thread
in
unsafethreads
]
except
cc
.
utils
.
CommentClientMaintenanceError
:
...
...
@@ -335,7 +344,7 @@ def single_thread(request, course_key, discussion_id, thread_id):
else
:
try
:
threads
,
query_params
=
get_threads
(
request
,
course
)
threads
,
query_params
=
get_threads
(
request
,
course
,
user_info
)
except
ValueError
:
return
HttpResponseBadRequest
(
"Invalid group_id"
)
threads
.
append
(
thread
.
to_dict
())
...
...
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