From d636c56af21ae5573ba8f4209271e2bfc839e3ec Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Fri, 16 May 2014 14:04:14 -0400 Subject: [PATCH] xml export of drafts was exporting everything now only exports the drafts into the draft subdir STUD-1627 --- common/lib/xmodule/xmodule/modulestore/mongo/base.py | 6 +++++- common/lib/xmodule/xmodule/modulestore/mongo/draft.py | 8 +++++++- common/lib/xmodule/xmodule/modulestore/xml_exporter.py | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo/base.py b/common/lib/xmodule/xmodule/modulestore/mongo/base.py index 3e579e10b9..2417e21ff8 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo/base.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo/base.py @@ -679,7 +679,11 @@ class MongoModuleStore(ModuleStoreWriteBase): and rules as kwargs below content (dict): fields to look for which have content scope. Follows same syntax and rules as kwargs below. - revision (str): the revision of the items you're looking for. + revision (str): the revision of the items you're looking for. (only 'draft' makes sense for + this modulestore. If you don't provide a revision, it won't retrieve any drafts. If you + say 'draft', it will only return drafts. If you want one of each matching xblock but + preferring draft to published, call this same method on the draft modulestore w/o a + revision qualifier.) kwargs (key=value): what to look for within the course. Common qualifiers are ``category`` or any field name. if the target field is a list, then it searches for the given value in the list not list equivalence. diff --git a/common/lib/xmodule/xmodule/modulestore/mongo/draft.py b/common/lib/xmodule/xmodule/modulestore/mongo/draft.py index d7226e3dc0..bfdbd72455 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo/draft.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo/draft.py @@ -95,7 +95,7 @@ class DraftModuleStore(MongoModuleStore): draft_loc = as_draft(location) return super(DraftModuleStore, self).create_xmodule(draft_loc, definition_data, metadata, system, fields) - def get_items(self, course_key, settings=None, content=None, **kwargs): + def get_items(self, course_key, settings=None, content=None, revision=None, **kwargs): """ Returns: list of XModuleDescriptor instances for the matching items within the course with @@ -108,6 +108,9 @@ class DraftModuleStore(MongoModuleStore): course_key (CourseKey): the course identifier settings: not used content: not used + revision (str): the revision of the items you're looking for. Only 'draft' makes sense for + this modulestore. None implies get one of either the draft or published for each + matching xblock preferring the draft if it exists. kwargs (key=value): what to look for within the course. Common qualifiers are ``category`` or any field name. if the target field is a list, then it searches for the given value in the list not list equivalence. @@ -118,6 +121,9 @@ class DraftModuleStore(MongoModuleStore): wrap_draft(item) for item in super(DraftModuleStore, self).get_items(course_key, revision='draft', **kwargs) ] + if revision == 'draft': + # the user only wants the drafts not everything w/ preference for draft + return draft_items draft_items_locations = {item.location for item in draft_items} non_draft_items = [ item for item in diff --git a/common/lib/xmodule/xmodule/modulestore/xml_exporter.py b/common/lib/xmodule/xmodule/modulestore/xml_exporter.py index be00414697..428cf0dcb6 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_exporter.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_exporter.py @@ -126,7 +126,7 @@ def export_to_xml(modulestore, contentstore, course_key, root_dir, course_dir, d # should we change the application, then this assumption will no longer # be valid if draft_modulestore is not None: - draft_verticals = draft_modulestore.get_items(course_key, category='vertical') + draft_verticals = draft_modulestore.get_items(course_key, category='vertical', revision='draft') if len(draft_verticals) > 0: draft_course_dir = export_fs.makeopendir(DRAFT_DIR) for draft_vertical in draft_verticals: