Commit e11706ef by Chris Dodge

change over the 'get all discussion models' to use get_items() which is better…

change over the 'get all discussion models' to use get_items() which is better supported in Mongo-backed stores
parent cc4482b4
...@@ -284,7 +284,7 @@ class ModuleStore(object): ...@@ -284,7 +284,7 @@ class ModuleStore(object):
""" """
raise NotImplementedError raise NotImplementedError
def get_items(self, location, depth=0): def get_items(self, location, course_id=None, depth=0):
""" """
Returns a list of XModuleDescriptor instances for the items Returns a list of XModuleDescriptor instances for the items
that match location. Any element of location that is None is treated that match location. Any element of location that is None is treated
......
...@@ -262,7 +262,7 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -262,7 +262,7 @@ class MongoModuleStore(ModuleStoreBase):
""" """
return self.get_item(location) return self.get_item(location)
def get_items(self, location, depth=0): def get_items(self, location, course_id=None, depth=0):
items = self.collection.find( items = self.collection.find(
location_to_query(location), location_to_query(location),
sort=[('revision', pymongo.ASCENDING)], sort=[('revision', pymongo.ASCENDING)],
......
...@@ -513,16 +513,22 @@ class XMLModuleStore(ModuleStoreBase): ...@@ -513,16 +513,22 @@ class XMLModuleStore(ModuleStoreBase):
raise NotImplementedError("XMLModuleStores can't guarantee that definitions" raise NotImplementedError("XMLModuleStores can't guarantee that definitions"
" are unique. Use get_instance.") " are unique. Use get_instance.")
def get_items(self, location, depth=0): def get_items(self, location, course_id=None, depth=0):
items = [] items = []
for _, modules in self.modules.iteritems():
for mod_loc, module in modules.iteritems():
def _add_get_items(self, location, modules):
for mod_loc, module in modules.iteritems():
# Locations match if each value in `location` is None or if the value from `location` # Locations match if each value in `location` is None or if the value from `location`
# matches the value from `mod_loc` # matches the value from `mod_loc`
if all(goal is None or goal == value for goal, value in zip(location, mod_loc)): if all(goal is None or goal == value for goal, value in zip(location, mod_loc)):
items.append(module) items.append(module)
if course_id is None:
for _, modules in self.modules.iteritems():
_add_get_items(self, location, modules)
else:
_add_get_items(self, location, self.modules[course_id])
return items return items
......
...@@ -127,6 +127,7 @@ def sort_map_entries(category_map): ...@@ -127,6 +127,7 @@ def sort_map_entries(category_map):
sort_map_entries(category_map["subcategories"][title]) sort_map_entries(category_map["subcategories"][title])
category_map["children"] = [x[0] for x in sorted(things, key=lambda x: x[1]["sort_key"])] category_map["children"] = [x[0] for x in sorted(things, key=lambda x: x[1]["sort_key"])]
def initialize_discussion_info(course): def initialize_discussion_info(course):
global _DISCUSSIONINFO global _DISCUSSIONINFO
...@@ -134,14 +135,16 @@ def initialize_discussion_info(course): ...@@ -134,14 +135,16 @@ def initialize_discussion_info(course):
return return
course_id = course.id course_id = course.id
all_modules = get_full_modules()[course_id]
discussion_id_map = {} discussion_id_map = {}
unexpanded_category_map = defaultdict(list) unexpanded_category_map = defaultdict(list)
for location, module in all_modules.items(): #all_modules = get_full_modules()[course_id]
if location.category == 'discussion':
all_modules = modulestore().get_items(['i4x', course.location.org, course.location.course, 'discussion', None], course_id=course_id)
for module in all_modules:
logging.debug('{0}'.format(module.location))
skip_module = False skip_module = False
for key in ('id', 'discussion_category', 'for'): for key in ('id', 'discussion_category', 'for'):
if key not in module.metadata: if key not in module.metadata:
...@@ -157,7 +160,7 @@ def initialize_discussion_info(course): ...@@ -157,7 +160,7 @@ def initialize_discussion_info(course):
sort_key = module.metadata.get('sort_key', title) sort_key = module.metadata.get('sort_key', title)
category = " / ".join([x.strip() for x in category.split("/")]) category = " / ".join([x.strip() for x in category.split("/")])
last_category = category.split("/")[-1] last_category = category.split("/")[-1]
discussion_id_map[id] = {"location": location, "title": last_category + " / " + title} discussion_id_map[id] = {"location": module.location, "title": last_category + " / " + title}
unexpanded_category_map[category].append({"title": title, "id": id, unexpanded_category_map[category].append({"title": title, "id": id,
"sort_key": sort_key, "start_date": module.start}) "sort_key": sort_key, "start_date": module.start})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment