fix: sort order will not be alphabetical (#30990)

Co-authored-by: adeel.tajamul <adeel.tajamul@arbisoft.com>
This commit is contained in:
Muhammad Adeel Tajamul
2022-09-19 12:24:46 +05:00
committed by GitHub
parent b8e466b55c
commit 1259c0e7a5
2 changed files with 14 additions and 18 deletions

View File

@@ -377,23 +377,12 @@ def get_courseware_topics(
courseware_topics = []
existing_topic_ids = set()
def get_xblock_sort_key(xblock):
"""
Get the sort key for the xblock (falling back to the discussion_target
setting if absent)
"""
return xblock.sort_key or xblock.discussion_target
def get_sorted_xblocks(category):
"""Returns key sorted xblocks by category"""
return sorted(xblocks_by_category[category], key=get_xblock_sort_key)
discussion_xblocks = get_accessible_discussion_xblocks(course, request.user)
xblocks_by_category = defaultdict(list)
for xblock in discussion_xblocks:
xblocks_by_category[xblock.discussion_category].append(xblock)
for category in sorted(xblocks_by_category.keys()):
for category in xblocks_by_category.keys():
children = []
for xblock in xblocks_by_category[category]:
if not topic_ids or xblock.discussion_id in topic_ids:
@@ -413,7 +402,11 @@ def get_courseware_topics(
discussion_topic = DiscussionTopic(
None,
category,
get_thread_list_url(request, course_key, [item.discussion_id for item in get_sorted_xblocks(category)]),
get_thread_list_url(
request,
course_key,
[item.discussion_id for item in xblocks_by_category[category]],
),
children,
None,
)
@@ -449,8 +442,8 @@ def get_non_courseware_topics(
"""
non_courseware_topics = []
existing_topic_ids = set()
sorted_topics = sorted(list(course.discussion_topics.items()), key=lambda item: item[1].get("sort_key", item[0]))
for name, entry in sorted_topics:
topics = list(course.discussion_topics.items())
for name, entry in topics:
if not topic_ids or entry['id'] in topic_ids:
discussion_topic = DiscussionTopic(
entry["id"], name, get_thread_list_url(request, course_key, [entry["id"]]),

View File

@@ -445,7 +445,10 @@ class GetCourseTopicsTest(CommentsServiceMockMixin, ForumsEnableMixin, UrlResetM
}
assert actual == expected
def test_sort_key(self):
def test_sort_key_doesnot_work(self):
"""
Test to check that providing sort_key doesn't change the sort order
"""
with self.store.bulk_operations(self.course.id, emit_signals=False):
self.course.discussion_topics = {
"W": {"id": "non-courseware-1", "sort_key": "Z"},
@@ -486,10 +489,10 @@ class GetCourseTopicsTest(CommentsServiceMockMixin, ForumsEnableMixin, UrlResetM
),
],
"non_courseware_topics": [
self.make_expected_tree("non-courseware-4", "Z"),
self.make_expected_tree("non-courseware-1", "W"),
self.make_expected_tree("non-courseware-2", "X"),
self.make_expected_tree("non-courseware-3", "Y"),
self.make_expected_tree("non-courseware-1", "W"),
self.make_expected_tree("non-courseware-4", "Z"),
],
}
assert actual == expected