get _cache_children to queyr both non-draft and draft versions of the children, then overwrite all non-drafts with the draft version, if available. This conforms with the semantics of the DraftMongoModuleStore
This commit is contained in:
@@ -138,7 +138,6 @@ def compute_unit_state(unit, subsection=None):
|
|||||||
'private' content is editabled and not visible in the LMS
|
'private' content is editabled and not visible in the LMS
|
||||||
"""
|
"""
|
||||||
|
|
||||||
logging.debug('****** is_draft = {0}'.format(getattr(unit, 'is_draft', False)))
|
|
||||||
if getattr(unit, 'is_draft', False):
|
if getattr(unit, 'is_draft', False):
|
||||||
try:
|
try:
|
||||||
modulestore('direct').get_item(unit.location)
|
modulestore('direct').get_item(unit.location)
|
||||||
|
|||||||
@@ -209,23 +209,46 @@ class DraftModuleStore(ModuleStoreBase):
|
|||||||
children.extend(item.get('definition', {}).get('children', []))
|
children.extend(item.get('definition', {}).get('children', []))
|
||||||
data[Location(item['location'])] = item
|
data[Location(item['location'])] = item
|
||||||
|
|
||||||
|
if depth == 0:
|
||||||
|
break;
|
||||||
|
|
||||||
# Load all children by id. See
|
# Load all children by id. See
|
||||||
# http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24or
|
# http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24or
|
||||||
# for or-query syntax
|
# for or-query syntax
|
||||||
|
to_process = []
|
||||||
if children:
|
if children:
|
||||||
|
# first get non-draft in a round-trip
|
||||||
query = {
|
query = {
|
||||||
'_id': {'$in': [namedtuple_to_son(Location(child)) for child in children]}
|
'_id': {'$in': [namedtuple_to_son(Location(child)) for child in children]}
|
||||||
}
|
}
|
||||||
to_process = list(self.collection.find(query))
|
to_process_non_drafts = list(self.collection.find(query))
|
||||||
|
|
||||||
|
to_process_dict = {}
|
||||||
|
for non_draft in to_process_non_drafts:
|
||||||
|
to_process_dict[Location(non_draft["_id"])] = non_draft
|
||||||
|
|
||||||
|
# now query all draft content in a round-trip
|
||||||
query = {
|
query = {
|
||||||
'_id': {'$in': [namedtuple_to_son(as_draft(Location(child))) for child in children]}
|
'_id': {'$in': [namedtuple_to_son(as_draft(Location(child))) for child in children]}
|
||||||
}
|
}
|
||||||
to_process.extend(list(self.collection.find(query)))
|
to_process_drafts = list(self.collection.find(query))
|
||||||
logging.debug('**** depth = {0}'.format(depth))
|
|
||||||
logging.debug('**** to_process = {0}'.format(to_process))
|
# now we have to go through all drafts and replace the non-draft
|
||||||
else:
|
# with the draft. This is because the semantics of the DraftStore is to
|
||||||
to_process = []
|
# always return the draft - if available
|
||||||
|
for draft in to_process_drafts:
|
||||||
|
draft_loc = Location(draft["_id"])
|
||||||
|
draft_as_non_draft_loc = draft_loc._replace(revision=None)
|
||||||
|
|
||||||
|
# does non-draft exist in the collection
|
||||||
|
# if so, replace it
|
||||||
|
if draft_as_non_draft_loc in to_process_dict:
|
||||||
|
to_process_dict[draft_as_non_draft_loc] = draft
|
||||||
|
|
||||||
|
# convert the dict - which is used for look ups - back into a list
|
||||||
|
for key, value in to_process_dict.iteritems():
|
||||||
|
to_process.append(value)
|
||||||
|
|
||||||
# If depth is None, then we just recurse until we hit all the descendents
|
# If depth is None, then we just recurse until we hit all the descendents
|
||||||
if depth is not None:
|
if depth is not None:
|
||||||
depth -= 1
|
depth -= 1
|
||||||
|
|||||||
Reference in New Issue
Block a user