change over the 'get all discussion models' to use get_items() which is better supported in Mongo-backed stores

This commit is contained in:
Chris Dodge
2013-01-09 15:53:22 -05:00
parent cc4482b4c9
commit e11706ef07
4 changed files with 34 additions and 25 deletions

View File

@@ -284,7 +284,7 @@ class ModuleStore(object):
"""
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
that match location. Any element of location that is None is treated

View File

@@ -262,7 +262,7 @@ class MongoModuleStore(ModuleStoreBase):
"""
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(
location_to_query(location),
sort=[('revision', pymongo.ASCENDING)],

View File

@@ -513,16 +513,22 @@ class XMLModuleStore(ModuleStoreBase):
raise NotImplementedError("XMLModuleStores can't guarantee that definitions"
" are unique. Use get_instance.")
def get_items(self, location, depth=0):
def get_items(self, location, course_id=None, depth=0):
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`
# matches the value from `mod_loc`
if all(goal is None or goal == value for goal, value in zip(location, mod_loc)):
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