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
a3c6faef
Commit
a3c6faef
authored
Oct 13, 2015
by
wajeeha-khalid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MA-1359 & MA-1457 DiscussionAPI: return response_count for thread GET/POST
parent
450e625d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
18 additions
and
20 deletions
+18
-20
lms/djangoapps/discussion_api/api.py
+3
-4
lms/djangoapps/discussion_api/serializers.py
+2
-10
lms/djangoapps/discussion_api/tests/test_api.py
+5
-2
lms/djangoapps/discussion_api/tests/test_serializers.py
+1
-2
lms/djangoapps/discussion_api/tests/test_views.py
+4
-1
lms/djangoapps/discussion_api/tests/utils.py
+1
-1
lms/djangoapps/discussion_api/views.py
+2
-0
No files found.
lms/djangoapps/discussion_api/api.py
View file @
a3c6faef
...
...
@@ -341,7 +341,7 @@ def get_thread_list(
if
result_page
!=
page
:
raise
Http404
results
=
[
ThreadSerializer
(
thread
,
remove_fields
=
[
'response_count'
],
context
=
context
)
.
data
for
thread
in
threads
]
results
=
[
ThreadSerializer
(
thread
,
context
=
context
)
.
data
for
thread
in
threads
]
ret
=
get_paginated_data
(
request
,
results
,
page
,
num_pages
)
ret
[
"text_search_rewrite"
]
=
text_search_rewrite
return
ret
...
...
@@ -555,7 +555,7 @@ def create_thread(request, thread_data):
):
thread_data
=
thread_data
.
copy
()
thread_data
[
"group_id"
]
=
get_cohort_id
(
user
,
course_key
)
serializer
=
ThreadSerializer
(
data
=
thread_data
,
remove_fields
=
[
'response_count'
],
context
=
context
)
serializer
=
ThreadSerializer
(
data
=
thread_data
,
context
=
context
)
actions_form
=
ThreadActionsForm
(
thread_data
)
if
not
(
serializer
.
is_valid
()
and
actions_form
.
is_valid
()):
raise
ValidationError
(
dict
(
serializer
.
errors
.
items
()
+
actions_form
.
errors
.
items
()))
...
...
@@ -642,8 +642,7 @@ def update_thread(request, thread_id, update_data):
"""
cc_thread
,
context
=
_get_thread_and_context
(
request
,
thread_id
)
_check_editable_fields
(
cc_thread
,
update_data
,
context
)
serializer
=
ThreadSerializer
(
cc_thread
,
remove_fields
=
[
'response_count'
],
data
=
update_data
,
partial
=
True
,
context
=
context
)
serializer
=
ThreadSerializer
(
cc_thread
,
data
=
update_data
,
partial
=
True
,
context
=
context
)
actions_form
=
ThreadActionsForm
(
update_data
)
if
not
(
serializer
.
is_valid
()
and
actions_form
.
is_valid
()):
raise
ValidationError
(
dict
(
serializer
.
errors
.
items
()
+
actions_form
.
errors
.
items
()))
...
...
lms/djangoapps/discussion_api/serializers.py
View file @
a3c6faef
...
...
@@ -197,24 +197,16 @@ class ThreadSerializer(_ContentSerializer):
non_endorsed_comment_list_url
=
serializers
.
SerializerMethodField
()
read
=
serializers
.
BooleanField
(
read_only
=
True
)
has_endorsed
=
serializers
.
BooleanField
(
read_only
=
True
,
source
=
"endorsed"
)
response_count
=
serializers
.
IntegerField
(
source
=
"resp_total"
,
read_only
=
True
)
response_count
=
serializers
.
IntegerField
(
source
=
"resp_total"
,
read_only
=
True
,
required
=
False
)
non_updatable_fields
=
NON_UPDATABLE_THREAD_FIELDS
# TODO: https://openedx.atlassian.net/browse/MA-1359
def
__init__
(
self
,
*
args
,
**
kwargs
):
remove_fields
=
kwargs
.
pop
(
'remove_fields'
,
None
)
super
(
ThreadSerializer
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
# Compensate for the fact that some threads in the comments service do
# not have the pinned field set
if
self
.
instance
and
self
.
instance
.
get
(
"pinned"
)
is
None
:
self
.
instance
[
"pinned"
]
=
False
if
self
.
instance
and
self
.
instance
.
get
(
"resp_total"
)
is
None
:
self
.
instance
[
"resp_total"
]
=
None
if
remove_fields
:
# for multiple fields in a list
for
field_name
in
remove_fields
:
self
.
fields
.
pop
(
field_name
)
def
get_pinned
(
self
,
obj
):
"""
...
...
@@ -286,7 +278,7 @@ class CommentSerializer(_ContentSerializer):
endorsed_by
=
serializers
.
SerializerMethodField
()
endorsed_by_label
=
serializers
.
SerializerMethodField
()
endorsed_at
=
serializers
.
SerializerMethodField
()
children
=
serializers
.
SerializerMethodField
()
children
=
serializers
.
SerializerMethodField
(
required
=
False
)
non_updatable_fields
=
NON_UPDATABLE_COMMENT_FIELDS
...
...
lms/djangoapps/discussion_api/tests/test_api.py
View file @
a3c6faef
...
...
@@ -1368,12 +1368,13 @@ class CreateThreadTest(
@mock.patch
(
"eventtracking.tracker.emit"
)
def
test_basic
(
self
,
mock_emit
):
self
.
register_post_thread_response
({
cs_thread
=
make_minimal_cs_thread
({
"id"
:
"test_id"
,
"username"
:
self
.
user
.
username
,
"created_at"
:
"2015-05-19T00:00:00Z"
,
"updated_at"
:
"2015-05-19T00:00:00Z"
,
})
self
.
register_post_thread_response
(
cs_thread
)
with
self
.
assert_signal_sent
(
api
,
'thread_created'
,
sender
=
None
,
user
=
self
.
user
,
exclude_args
=
(
'post'
,)):
actual
=
create_thread
(
self
.
request
,
self
.
minimal_data
)
expected
=
{
...
...
@@ -1403,7 +1404,8 @@ class CreateThreadTest(
"non_endorsed_comment_list_url"
:
None
,
"editable_fields"
:
[
"abuse_flagged"
,
"following"
,
"raw_body"
,
"title"
,
"topic_id"
,
"type"
,
"voted"
],
'read'
:
False
,
'has_endorsed'
:
False
'has_endorsed'
:
False
,
'response_count'
:
0
,
}
self
.
assertEqual
(
actual
,
expected
)
self
.
assertEqual
(
...
...
@@ -1949,6 +1951,7 @@ class UpdateThreadTest(
"editable_fields"
:
[
"abuse_flagged"
,
"following"
,
"raw_body"
,
"title"
,
"topic_id"
,
"type"
,
"voted"
],
'read'
:
False
,
'has_endorsed'
:
False
,
'response_count'
:
0
}
self
.
assertEqual
(
actual
,
expected
)
self
.
assertEqual
(
...
...
lms/djangoapps/discussion_api/tests/test_serializers.py
View file @
a3c6faef
...
...
@@ -211,7 +211,6 @@ class ThreadSerializerSerializationTest(SerializerTestMixin, SharedModuleStoreTe
"editable_fields"
:
[
"abuse_flagged"
,
"following"
,
"voted"
],
"read"
:
False
,
"has_endorsed"
:
False
,
"response_count"
:
None
,
}
self
.
assertEqual
(
self
.
serialize
(
thread
),
expected
)
...
...
@@ -262,7 +261,7 @@ class ThreadSerializerSerializationTest(SerializerTestMixin, SharedModuleStoreTe
del
thread_data
[
"resp_total"
]
self
.
register_get_thread_response
(
thread_data
)
serialized
=
self
.
serialize
(
Thread
(
id
=
thread_data
[
"id"
]))
self
.
assert
IsNone
(
serialized
[
"response_count"
],
None
)
self
.
assert
NotIn
(
"response_count"
,
serialized
)
@ddt.ddt
...
...
lms/djangoapps/discussion_api/tests/test_views.py
View file @
a3c6faef
...
...
@@ -400,12 +400,13 @@ class ThreadViewSetCreateTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
def
test_basic
(
self
):
self
.
register_get_user_response
(
self
.
user
)
self
.
register_post_thread_response
({
cs_thread
=
make_minimal_cs_thread
({
"id"
:
"test_thread"
,
"username"
:
self
.
user
.
username
,
"created_at"
:
"2015-05-19T00:00:00Z"
,
"updated_at"
:
"2015-05-19T00:00:00Z"
,
})
self
.
register_post_thread_response
(
cs_thread
)
request_data
=
{
"course_id"
:
unicode
(
self
.
course
.
id
),
"topic_id"
:
"test_topic"
,
...
...
@@ -441,6 +442,7 @@ class ThreadViewSetCreateTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"editable_fields"
:
[
"abuse_flagged"
,
"following"
,
"raw_body"
,
"title"
,
"topic_id"
,
"type"
,
"voted"
],
"read"
:
False
,
"has_endorsed"
:
False
,
"response_count"
:
0
,
}
response
=
self
.
client
.
post
(
self
.
url
,
...
...
@@ -536,6 +538,7 @@ class ThreadViewSetPartialUpdateTest(DiscussionAPIViewTestMixin, ModuleStoreTest
"editable_fields"
:
[
"abuse_flagged"
,
"following"
,
"raw_body"
,
"title"
,
"topic_id"
,
"type"
,
"voted"
],
"read"
:
False
,
"has_endorsed"
:
False
,
"response_count"
:
0
,
}
response
=
self
.
client
.
patch
(
# pylint: disable=no-member
self
.
url
,
...
...
lms/djangoapps/discussion_api/tests/utils.py
View file @
a3c6faef
...
...
@@ -329,9 +329,9 @@ def make_minimal_cs_thread(overrides=None):
"comments_count"
:
0
,
"unread_comments_count"
:
0
,
"children"
:
[],
"resp_total"
:
0
,
"read"
:
False
,
"endorsed"
:
False
,
"resp_total"
:
0
,
}
ret
.
update
(
overrides
or
{})
return
ret
...
...
lms/djangoapps/discussion_api/views.py
View file @
a3c6faef
...
...
@@ -229,6 +229,8 @@ class ThreadViewSet(_ViewMixin, DeveloperErrorViewMixin, ViewSet):
* has_endorsed: Boolean indicating whether this thread has been answered
* response_count: The number of direct responses for a thread
**DELETE response values:
No content is returned for a DELETE request
...
...
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