Skip to content
Snippets Groups Projects
Commit 4e770988 authored by Giulio Gratta's avatar Giulio Gratta
Browse files

added course level feature flag for forum alpha sorting as well as tests

parent e0471007
No related merge requests found
......@@ -198,10 +198,8 @@ class CourseFields(object):
tabs = List(help="List of tabs to enable in this course", scope=Scope.settings)
end_of_course_survey_url = String(help="Url for the end-of-course survey", scope=Scope.settings)
discussion_blackouts = List(help="List of pairs of start/end dates for discussion blackouts", scope=Scope.settings)
discussion_topics = Dict(
help="Map of topics names to ids",
scope=Scope.settings
)
discussion_topics = Dict(help="Map of topics names to ids", scope=Scope.settings)
discussion_sort_alpha = Boolean(scope=Scope.settings, default=False, help="Sort forum categories and subcategories alphabetically.")
testcenter_info = Dict(help="Dictionary of Test Center info", scope=Scope.settings)
announcement = Date(help="Date this course is announced", scope=Scope.settings)
cohort_config = Dict(help="Dictionary defining cohort configuration", scope=Scope.settings)
......
......@@ -2,6 +2,7 @@ from django.test import TestCase
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from django_comment_common.models import Role, Permission
from factories import RoleFactory
from copy import deepcopy
import django_comment_client.utils as utils
......@@ -28,6 +29,124 @@ class DictionaryTestCase(TestCase):
expected = {'cats': 'meow', 'dogs': 'woof', 'lions': 'roar', 'ducks': 'quack'}
self.assertEqual(utils.merge_dict(d1, d2), expected)
def test_sort(self):
d1 = {
'entries': {
u'General': {
'sort_key': u'General'
}
},
'subcategories': {
u'Tests': {
'sort_key': u'Tests',
'subcategories': {},
'entries': {
u'Quizzes': {
'sort_key': None
}, u'All': {
'sort_key': None
}, u'Final Exam': {
'sort_key': None
},
}
},
u'Assignments': {
'sort_key': u'Assignments',
'subcategories': {},
'entries': {
u'Homework': {
'sort_key': None
},
u'All': {
'sort_key': None
},
}
}
}
}
expected_1 = {
'entries': {
u'General': {
'sort_key': u'General'
}
},
'children': [u'Assignments', u'General', u'Tests'],
'subcategories': {
u'Tests': {
'sort_key': u'Tests',
'subcategories': {},
'children': [u'All', u'Final Exam', u'Quizzes'],
'entries': {
u'All': {
'sort_key': 'All'
}, u'Final Exam': {
'sort_key': 'Final Exam'
}, u'Quizzes': {
'sort_key': 'Quizzes'
}
}
},
u'Assignments': {
'sort_key': u'Assignments',
'subcategories': {},
'children': [u'All', u'Homework'],
'entries': {
u'Homework': {
'sort_key': 'Homework'
},
u'All': {
'sort_key': 'All'
},
}
}
}
}
expected_2 = {
'entries': {
u'General': {
'sort_key': u'General'
}
},
'children': [u'Assignments', u'General', u'Tests'],
'subcategories': {
u'Tests': {
'sort_key': u'Tests',
'subcategories': {},
'children': [u'Quizzes', u'All', u'Final Exam'],
'entries': {
u'Quizzes': {
'sort_key': None
}, u'All': {
'sort_key': None
}, u'Final Exam': {
'sort_key': None
},
}
},
u'Assignments': {
'sort_key': u'Assignments',
'subcategories': {},
'children': [u'All', u'Homework'],
'entries': {
u'Homework': {
'sort_key': None
},
u'All': {
'sort_key': None
},
}
}
}
}
d2 = deepcopy(d1)
utils.sort_map_entries(d1, True)
utils.sort_map_entries(d2, False)
self.assertEqual(d1, expected_1)
self.assertEqual(d2, expected_2)
class AccessUtilsTestCase(TestCase):
def setUp(self):
......
......@@ -125,16 +125,16 @@ def filter_unstarted_categories(category_map):
return result_map
def sort_map_entries(category_map):
def sort_map_entries(category_map, sort_alpha):
things = []
for title, entry in category_map["entries"].items():
if entry["sort_key"] == None:
if entry["sort_key"] == None and sort_alpha:
entry["sort_key"] = title
things.append((title, entry))
for title, category in category_map["subcategories"].items():
things.append((title, category))
sort_map_entries(category_map["subcategories"][title])
sort_map_entries(category_map["subcategories"][title], sort_alpha)
category_map["children"] = [x[0] for x in sorted(things, key=lambda x: x[1]["sort_key"])]
......@@ -213,7 +213,8 @@ def initialize_discussion_info(course):
category_map['entries'][topic] = {"id": entry["id"],
"sort_key": entry.get("sort_key", topic),
"start_date": datetime.now(UTC())}
sort_map_entries(category_map)
sort_map_entries(category_map, course.discussion_sort_alpha)
_DISCUSSIONINFO[course.id]['id_map'] = discussion_id_map
_DISCUSSIONINFO[course.id]['category_map'] = category_map
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment