Allow to set the default topic for new Discussion posts
This commit is contained in:
@@ -293,7 +293,10 @@ class CourseFields(object):
|
||||
'{"id": "i4x-InstitutionName-CourseNumber-course-CourseRun"}. For example, one discussion '
|
||||
'category may be "Lydian Mode": {"id": "i4x-UniversityX-MUS101-course-2015_T1"}. The "id" '
|
||||
'value for each category must be unique. In "id" values, the only special characters that are '
|
||||
'supported are underscore, hyphen, and period.'
|
||||
'supported are underscore, hyphen, and period. You can also specify a category as the default '
|
||||
'for new posts in the Discussion page by setting its "default" attribute to true. For example, '
|
||||
'"Lydian Mode": {"id": "i4x-UniversityX-MUS101-course-2015_T1", "default": true}.'
|
||||
|
||||
),
|
||||
scope=Scope.settings
|
||||
)
|
||||
|
||||
@@ -59,7 +59,8 @@
|
||||
course_settings: courseSettings,
|
||||
discussionBoardView: discussionBoardView,
|
||||
mode: 'tab',
|
||||
startHeader: 2
|
||||
startHeader: 2,
|
||||
topicId: options.defaultTopicId
|
||||
});
|
||||
newPostView.render();
|
||||
|
||||
|
||||
@@ -57,7 +57,8 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str
|
||||
contentInfo: ${annotated_content_info | n, dump_js_escaped_json},
|
||||
courseName: '${course.display_name_with_default | n, js_escaped_string}',
|
||||
courseSettings: ${course_settings | n, dump_js_escaped_json},
|
||||
isCommentableDivided: ${is_commentable_divided | n, dump_js_escaped_json}
|
||||
isCommentableDivided: ${is_commentable_divided | n, dump_js_escaped_json},
|
||||
defaultTopicId: '${discussion_default_topic_id | n, js_escaped_string}'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,6 +32,7 @@ from django_comment_common.models import CourseDiscussionSettings, ForumsConfig
|
||||
from django_comment_common.utils import ThreadContext
|
||||
from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
|
||||
from lms.djangoapps.discussion import views
|
||||
from lms.djangoapps.discussion.views import _get_discussion_default_topic_id
|
||||
from lms.djangoapps.discussion.views import course_discussions_settings_handler
|
||||
from lms.djangoapps.teams.tests.factories import CourseTeamFactory
|
||||
from lms.lib.comment_client.utils import CommentClientPaginatedResult
|
||||
@@ -1884,3 +1885,35 @@ class CourseDiscussionsHandlerTestCase(DividedDiscussionsTestCase):
|
||||
CourseDiscussionSettings.COHORT, CourseDiscussionSettings.ENROLLMENT_TRACK
|
||||
]
|
||||
self.assertEqual(response, expected_response)
|
||||
|
||||
|
||||
class DefaultTopicIdGetterTestCase(ModuleStoreTestCase):
|
||||
"""
|
||||
Tests the `_get_discussion_default_topic_id` helper.
|
||||
"""
|
||||
|
||||
def test_no_default_topic(self):
|
||||
discussion_topics = {
|
||||
'dummy discussion': {
|
||||
'id': 'dummy_discussion_id',
|
||||
},
|
||||
}
|
||||
course = CourseFactory.create(discussion_topics=discussion_topics)
|
||||
expected_id = None
|
||||
result = _get_discussion_default_topic_id(course)
|
||||
self.assertEqual(expected_id, result)
|
||||
|
||||
def test_default_topic_id(self):
|
||||
discussion_topics = {
|
||||
'dummy discussion': {
|
||||
'id': 'dummy_discussion_id',
|
||||
},
|
||||
'another discussion': {
|
||||
'id': 'another_discussion_id',
|
||||
'default': True,
|
||||
},
|
||||
}
|
||||
course = CourseFactory.create(discussion_topics=discussion_topics)
|
||||
expected_id = 'another_discussion_id'
|
||||
result = _get_discussion_default_topic_id(course)
|
||||
self.assertEqual(expected_id, result)
|
||||
|
||||
@@ -387,6 +387,12 @@ def _create_base_discussion_view_context(request, course_key):
|
||||
}
|
||||
|
||||
|
||||
def _get_discussion_default_topic_id(course):
|
||||
for topic, entry in course.discussion_topics.items():
|
||||
if entry.get('default') is True:
|
||||
return entry['id']
|
||||
|
||||
|
||||
def _create_discussion_board_context(request, course_key, discussion_id=None, thread_id=None):
|
||||
"""
|
||||
Returns the template context for rendering the discussion board.
|
||||
@@ -447,6 +453,8 @@ def _create_discussion_board_context(request, course_key, discussion_id=None, th
|
||||
'upgrade_link': check_and_get_upgrade_link(request, user, course.id),
|
||||
'upgrade_price': get_cosmetic_verified_display_price(course),
|
||||
# ENDTODO
|
||||
# If the default topic id is None the front-end code will look for a topic that contains "General"
|
||||
'discussion_default_topic_id': _get_discussion_default_topic_id(course),
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
Reference in New Issue
Block a user