Fix discussion category map for self-paced courses
Prevents start date alone from being used to filter out categories in self-paced courses during construction of the category map. ECOM-4017.
This commit is contained in:
@@ -666,6 +666,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase):
|
||||
self.create_discussion("Chapter 2 / Section 1 / Subsection 2", "Discussion", start=later)
|
||||
self.create_discussion("Chapter 3 / Section 1", "Discussion", start=later)
|
||||
|
||||
self.assertFalse(self.course.self_paced)
|
||||
self.assert_category_map_equals(
|
||||
{
|
||||
"entries": {},
|
||||
@@ -696,7 +697,102 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase):
|
||||
"children": ["Chapter 1", "Chapter 2"]
|
||||
}
|
||||
)
|
||||
self.maxDiff = None
|
||||
|
||||
def test_self_paced_start_date_filter(self):
|
||||
self.course.self_paced = True
|
||||
self.course.save()
|
||||
|
||||
now = datetime.datetime.now()
|
||||
later = datetime.datetime.max
|
||||
self.create_discussion("Chapter 1", "Discussion 1", start=now)
|
||||
self.create_discussion("Chapter 1", "Discussion 2", start=later)
|
||||
self.create_discussion("Chapter 2", "Discussion", start=now)
|
||||
self.create_discussion("Chapter 2 / Section 1 / Subsection 1", "Discussion", start=later)
|
||||
self.create_discussion("Chapter 2 / Section 1 / Subsection 2", "Discussion", start=later)
|
||||
self.create_discussion("Chapter 3 / Section 1", "Discussion", start=later)
|
||||
|
||||
self.assertTrue(self.course.self_paced)
|
||||
self.assert_category_map_equals(
|
||||
{
|
||||
"entries": {},
|
||||
"subcategories": {
|
||||
"Chapter 1": {
|
||||
"entries": {
|
||||
"Discussion 1": {
|
||||
"id": "discussion1",
|
||||
"sort_key": None,
|
||||
"is_cohorted": False,
|
||||
},
|
||||
"Discussion 2": {
|
||||
"id": "discussion2",
|
||||
"sort_key": None,
|
||||
"is_cohorted": False,
|
||||
}
|
||||
},
|
||||
"subcategories": {},
|
||||
"children": ["Discussion 1", "Discussion 2"]
|
||||
},
|
||||
"Chapter 2": {
|
||||
"entries": {
|
||||
"Discussion": {
|
||||
"id": "discussion3",
|
||||
"sort_key": None,
|
||||
"is_cohorted": False,
|
||||
}
|
||||
},
|
||||
"subcategories": {
|
||||
"Section 1": {
|
||||
"entries": {},
|
||||
"subcategories": {
|
||||
"Subsection 1": {
|
||||
"entries": {
|
||||
"Discussion": {
|
||||
"id": "discussion4",
|
||||
"sort_key": None,
|
||||
"is_cohorted": False,
|
||||
}
|
||||
},
|
||||
"subcategories": {},
|
||||
"children": ["Discussion"]
|
||||
},
|
||||
"Subsection 2": {
|
||||
"entries": {
|
||||
"Discussion": {
|
||||
"id": "discussion5",
|
||||
"sort_key": None,
|
||||
"is_cohorted": False,
|
||||
}
|
||||
},
|
||||
"subcategories": {},
|
||||
"children": ["Discussion"]
|
||||
}
|
||||
},
|
||||
"children": ["Subsection 1", "Subsection 2"]
|
||||
}
|
||||
},
|
||||
"children": ["Discussion", "Section 1"]
|
||||
},
|
||||
"Chapter 3": {
|
||||
"entries": {},
|
||||
"subcategories": {
|
||||
"Section 1": {
|
||||
"entries": {
|
||||
"Discussion": {
|
||||
"id": "discussion6",
|
||||
"sort_key": None,
|
||||
"is_cohorted": False,
|
||||
}
|
||||
},
|
||||
"subcategories": {},
|
||||
"children": ["Discussion"]
|
||||
}
|
||||
},
|
||||
"children": ["Section 1"]
|
||||
}
|
||||
},
|
||||
"children": ["Chapter 1", "Chapter 2", "Chapter 3"]
|
||||
}
|
||||
)
|
||||
|
||||
def test_sort_inline_explicit(self):
|
||||
self.create_discussion("Chapter", "Discussion 1", sort_key="D")
|
||||
|
||||
@@ -198,7 +198,7 @@ def get_discussion_id_map(course, user):
|
||||
return dict(map(get_discussion_id_map_entry, get_accessible_discussion_modules(course, user)))
|
||||
|
||||
|
||||
def _filter_unstarted_categories(category_map):
|
||||
def _filter_unstarted_categories(category_map, course):
|
||||
"""
|
||||
Returns a subset of categories from the provided map which have not yet met the start date
|
||||
Includes information about category children, subcategories (different), and entries
|
||||
@@ -221,7 +221,7 @@ def _filter_unstarted_categories(category_map):
|
||||
|
||||
for child in unfiltered_map["children"]:
|
||||
if child in unfiltered_map["entries"]:
|
||||
if unfiltered_map["entries"][child]["start_date"] <= now:
|
||||
if course.self_paced or unfiltered_map["entries"][child]["start_date"] <= now:
|
||||
filtered_map["children"].append(child)
|
||||
filtered_map["entries"][child] = {}
|
||||
for key in unfiltered_map["entries"][child]:
|
||||
@@ -230,7 +230,7 @@ def _filter_unstarted_categories(category_map):
|
||||
else:
|
||||
log.debug(u"Filtering out:%s with start_date: %s", child, unfiltered_map["entries"][child]["start_date"])
|
||||
else:
|
||||
if unfiltered_map["subcategories"][child]["start_date"] < now:
|
||||
if course.self_paced or unfiltered_map["subcategories"][child]["start_date"] < now:
|
||||
filtered_map["children"].append(child)
|
||||
filtered_map["subcategories"][child] = {}
|
||||
unfiltered_queue.append(unfiltered_map["subcategories"][child])
|
||||
@@ -382,7 +382,7 @@ def get_discussion_category_map(course, user, cohorted_if_in_list=False, exclude
|
||||
|
||||
_sort_map_entries(category_map, course.discussion_sort_alpha)
|
||||
|
||||
return _filter_unstarted_categories(category_map) if exclude_unstarted else category_map
|
||||
return _filter_unstarted_categories(category_map, course) if exclude_unstarted else category_map
|
||||
|
||||
|
||||
def discussion_category_id_access(course, user, discussion_id):
|
||||
|
||||
@@ -190,7 +190,6 @@ if ENV_TOKENS.get('SESSION_COOKIE_NAME', None):
|
||||
SESSION_COOKIE_NAME = str(ENV_TOKENS.get('SESSION_COOKIE_NAME'))
|
||||
|
||||
BOOK_URL = ENV_TOKENS['BOOK_URL']
|
||||
MEDIA_URL = ENV_TOKENS['MEDIA_URL']
|
||||
LOG_DIR = ENV_TOKENS['LOG_DIR']
|
||||
|
||||
CACHES = ENV_TOKENS['CACHES']
|
||||
|
||||
Reference in New Issue
Block a user