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
72ccb87d
Commit
72ccb87d
authored
Nov 21, 2014
by
E. Kolpakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed changing thread type
parent
c67fc0d9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
3 deletions
+73
-3
lms/djangoapps/django_comment_client/base/views.py
+14
-1
lms/djangoapps/django_comment_client/tests/test_utils.py
+41
-1
lms/djangoapps/django_comment_client/utils.py
+17
-0
lms/lib/comment_client/thread.py
+1
-1
No files found.
lms/djangoapps/django_comment_client/base/views.py
View file @
72ccb87d
...
@@ -26,7 +26,8 @@ from django_comment_client.utils import (
...
@@ -26,7 +26,8 @@ from django_comment_client.utils import (
get_ability
,
get_ability
,
JsonError
,
JsonError
,
JsonResponse
,
JsonResponse
,
safe_content
safe_content
,
get_discussion_categories_ids
)
)
from
django_comment_client.permissions
import
check_permissions_by_view
,
cached_has_permission
from
django_comment_client.permissions
import
check_permissions_by_view
,
cached_has_permission
import
lms.lib.comment_client
as
cc
import
lms.lib.comment_client
as
cc
...
@@ -164,6 +165,18 @@ def update_thread(request, course_id, thread_id):
...
@@ -164,6 +165,18 @@ def update_thread(request, course_id, thread_id):
thread
=
cc
.
Thread
.
find
(
thread_id
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
thread
.
body
=
request
.
POST
[
"body"
]
thread
.
body
=
request
.
POST
[
"body"
]
thread
.
title
=
request
.
POST
[
"title"
]
thread
.
title
=
request
.
POST
[
"title"
]
# The following checks should avoid issues we've seen during deploys, where end users are hitting an updated server
# while their browser still has the old client code. This will avoid erasing present values in those cases.
if
"thread_type"
in
request
.
POST
:
thread
.
thread_type
=
request
.
POST
[
"thread_type"
]
if
"commentable_id"
in
request
.
POST
:
course
=
get_course_with_access
(
request
.
user
,
'load'
,
course_key
)
commentable_ids
=
get_discussion_categories_ids
(
course
)
if
request
.
POST
.
get
(
"commentable_id"
)
in
commentable_ids
:
thread
.
commentable_id
=
request
.
POST
[
"commentable_id"
]
else
:
return
JsonError
(
_
(
"Topic doesn't exist"
))
thread
.
save
()
thread
.
save
()
if
request
.
is_ajax
():
if
request
.
is_ajax
():
return
ajax_content_response
(
request
,
course_key
,
thread
.
to_dict
())
return
ajax_content_response
(
request
,
course_key
,
thread
.
to_dict
())
...
...
lms/djangoapps/django_comment_client/tests/test_utils.py
View file @
72ccb87d
...
@@ -42,7 +42,7 @@ class DictionaryTestCase(TestCase):
...
@@ -42,7 +42,7 @@ class DictionaryTestCase(TestCase):
@override_settings
(
MODULESTORE
=
TEST_DATA_MONGO_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MONGO_MODULESTORE
)
class
AccessUtilsTestCase
(
TestCase
):
class
AccessUtilsTestCase
(
ModuleStore
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
()
self
.
course
=
CourseFactory
.
create
()
self
.
course_id
=
self
.
course
.
id
self
.
course_id
=
self
.
course
.
id
...
@@ -564,6 +564,46 @@ class CategoryMapTestCase(ModuleStoreTestCase):
...
@@ -564,6 +564,46 @@ class CategoryMapTestCase(ModuleStoreTestCase):
}
}
)
)
def
test_ids_empty
(
self
):
self
.
assertEqual
(
utils
.
get_discussion_categories_ids
(
self
.
course
),
[])
def
test_ids_configured_topics
(
self
):
self
.
course
.
discussion_topics
=
{
"Topic A"
:
{
"id"
:
"Topic_A"
},
"Topic B"
:
{
"id"
:
"Topic_B"
},
"Topic C"
:
{
"id"
:
"Topic_C"
}
}
self
.
assertItemsEqual
(
utils
.
get_discussion_categories_ids
(
self
.
course
),
[
"Topic_A"
,
"Topic_B"
,
"Topic_C"
]
)
def
test_ids_inline
(
self
):
self
.
create_discussion
(
"Chapter 1"
,
"Discussion 1"
)
self
.
create_discussion
(
"Chapter 1"
,
"Discussion 2"
)
self
.
create_discussion
(
"Chapter 2"
,
"Discussion"
)
self
.
create_discussion
(
"Chapter 2 / Section 1 / Subsection 1"
,
"Discussion"
)
self
.
create_discussion
(
"Chapter 2 / Section 1 / Subsection 2"
,
"Discussion"
)
self
.
create_discussion
(
"Chapter 3 / Section 1"
,
"Discussion"
)
self
.
assertItemsEqual
(
utils
.
get_discussion_categories_ids
(
self
.
course
),
[
"discussion1"
,
"discussion2"
,
"discussion3"
,
"discussion4"
,
"discussion5"
,
"discussion6"
]
)
def
test_ids_mixed
(
self
):
self
.
course
.
discussion_topics
=
{
"Topic A"
:
{
"id"
:
"Topic_A"
},
"Topic B"
:
{
"id"
:
"Topic_B"
},
"Topic C"
:
{
"id"
:
"Topic_C"
}
}
self
.
create_discussion
(
"Chapter 1"
,
"Discussion 1"
)
self
.
create_discussion
(
"Chapter 2"
,
"Discussion"
)
self
.
create_discussion
(
"Chapter 2 / Section 1 / Subsection 1"
,
"Discussion"
)
self
.
assertItemsEqual
(
utils
.
get_discussion_categories_ids
(
self
.
course
),
[
"Topic_A"
,
"Topic_B"
,
"Topic_C"
,
"discussion1"
,
"discussion2"
,
"discussion3"
]
)
class
JsonResponseTestCase
(
TestCase
,
UnicodeTestMixin
):
class
JsonResponseTestCase
(
TestCase
,
UnicodeTestMixin
):
def
_test_unicode_data
(
self
,
text
):
def
_test_unicode_data
(
self
,
text
):
...
...
lms/djangoapps/django_comment_client/utils.py
View file @
72ccb87d
...
@@ -203,6 +203,23 @@ def get_discussion_category_map(course):
...
@@ -203,6 +203,23 @@ def get_discussion_category_map(course):
return
_filter_unstarted_categories
(
category_map
)
return
_filter_unstarted_categories
(
category_map
)
def
get_discussion_categories_ids
(
course
):
"""
Returns a list of available ids of categories for the course.
"""
ids
=
[]
queue
=
[
get_discussion_category_map
(
course
)]
while
queue
:
category_map
=
queue
.
pop
()
for
child
in
category_map
[
"children"
]:
if
child
in
category_map
[
"entries"
]:
ids
.
append
(
category_map
[
"entries"
][
child
][
"id"
])
else
:
queue
.
append
(
category_map
[
"subcategories"
][
child
])
return
ids
class
JsonResponse
(
HttpResponse
):
class
JsonResponse
(
HttpResponse
):
def
__init__
(
self
,
data
=
None
):
def
__init__
(
self
,
data
=
None
):
content
=
json
.
dumps
(
data
,
cls
=
i4xEncoder
)
content
=
json
.
dumps
(
data
,
cls
=
i4xEncoder
)
...
...
lms/lib/comment_client/thread.py
View file @
72ccb87d
...
@@ -22,7 +22,7 @@ class Thread(models.Model):
...
@@ -22,7 +22,7 @@ class Thread(models.Model):
updatable_fields
=
[
updatable_fields
=
[
'title'
,
'body'
,
'anonymous'
,
'anonymous_to_peers'
,
'course_id'
,
'title'
,
'body'
,
'anonymous'
,
'anonymous_to_peers'
,
'course_id'
,
'closed'
,
'user_id'
,
'commentable_id'
,
'group_id'
,
'group_name'
,
'pinned'
'closed'
,
'user_id'
,
'commentable_id'
,
'group_id'
,
'group_name'
,
'pinned'
,
'thread_type'
]
]
metric_tag_fields
=
[
metric_tag_fields
=
[
...
...
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