diff --git a/common/lib/xmodule/xmodule/modulestore/__init__.py b/common/lib/xmodule/xmodule/modulestore/__init__.py index 3115d2f4c7..c94551008d 100644 --- a/common/lib/xmodule/xmodule/modulestore/__init__.py +++ b/common/lib/xmodule/xmodule/modulestore/__init__.py @@ -588,6 +588,25 @@ class ModuleStoreWriteBase(ModuleStoreReadBase, ModuleStoreWrite): result[field.scope][field_name] = value return result + def create_course(self, org, course, run, user_id, fields=None, runtime=None, **kwargs): + """ + Creates any necessary other things for the course as a side effect and doesn't return + anything useful. The real subclass should call this before it returns the course. + """ + # clone a default 'about' overview module as well + about_location = self.make_course_key(org, course, run).make_usage_key('about', 'overview') + + about_descriptor = XBlock.load_class('about') + overview_template = about_descriptor.get_template('overview.yaml') + self.create_item( + user_id, + about_location.course_key, + about_location.block_type, + block_id=about_location.block_id, + definition_data=overview_template.get('data'), + runtime=runtime + ) + def clone_course(self, source_course_id, dest_course_id, user_id, fields=None, **kwargs): """ This base method just copies the assets. The lower level impls must do the actual cloning of diff --git a/common/lib/xmodule/xmodule/modulestore/mongo/base.py b/common/lib/xmodule/xmodule/modulestore/mongo/base.py index ef955d773e..e68b499e8b 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo/base.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo/base.py @@ -29,7 +29,6 @@ from importlib import import_module from xmodule.errortracker import null_error_tracker, exc_info_to_str from xmodule.mako_module import MakoDescriptorSystem from xmodule.error_module import ErrorDescriptor -from xmodule.html_module import AboutDescriptor from xblock.runtime import KvsFieldData from xblock.exceptions import InvalidScopeError from xblock.fields import Scope, ScopeIds, Reference, ReferenceList, ReferenceValueDict @@ -948,22 +947,14 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase): if courses.count() > 0: raise DuplicateCourseError(course_id, courses[0]['_id']) - course = self.create_item(user_id, course_id, 'course', course_id.run, fields=fields, **kwargs) + xblock = self.create_item(user_id, course_id, 'course', course_id.run, fields=fields, **kwargs) - # clone a default 'about' overview module as well - about_location = course_id.make_usage_key('about', 'overview') - - overview_template = AboutDescriptor.get_template('overview.yaml') - self.create_item( - user_id, - about_location.course_key, - about_location.block_type, - block_id=about_location.block_id, - definition_data=overview_template.get('data'), - runtime=course.system + # create any other necessary things as a side effect + super(MongoModuleStore, self).create_course( + org, course, run, user_id, runtime=xblock.runtime, **kwargs ) - return course + return xblock def create_xblock( self, runtime, course_key, block_type, block_id=None, fields=None, diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py index 9755744373..2a5fa3b7be 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py @@ -1091,6 +1091,7 @@ class SplitMongoModuleStore(ModuleStoreWriteBase): if fields is not None: self._update_search_targets(index_entry, fields) self.db_connection.insert_course_index(index_entry) + # expensive hack to persist default field values set in __init__ method (e.g., wiki_slug) course = self.get_course(locator, **kwargs) return self.update_item(course, user_id, **kwargs) diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py index 378d51b0d3..02f3ca8141 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py @@ -86,6 +86,7 @@ class DraftVersioningModuleStore(ModuleStoreDraftAndPublished, SplitMongoModuleS definition_locator=None, fields=None, force=False, continue_version=False, **kwargs ): + course_key = self._map_revision_to_branch(course_key) item = super(DraftVersioningModuleStore, self).create_item( user_id, course_key, block_type, block_id=block_id, definition_locator=definition_locator, fields=fields, @@ -98,6 +99,7 @@ class DraftVersioningModuleStore(ModuleStoreDraftAndPublished, SplitMongoModuleS self, user_id, parent_usage_key, block_type, block_id=None, fields=None, continue_version=False, **kwargs ): + parent_usage_key = self._map_revision_to_branch(parent_usage_key) item = super(DraftVersioningModuleStore, self).create_child( user_id, parent_usage_key, block_type, block_id=block_id, fields=fields, continue_version=continue_version, **kwargs diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index 91c7c04b06..6a6d8843d3 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -348,12 +348,6 @@ class ModuleStoreTestCase(TestCase): self.user.id, self.toy_loc, "about", block_id="end_date", fields={"data": "TBD"} ) - self.store.create_item( - self.user.id, self.toy_loc, "about", block_id="overview", - fields={ - "data": "
\n

About This Course

\n

Include your long course description here. The long course description should contain 150-400 words.

\n\n

This is paragraph 2 of the long course description. Add more paragraphs as needed. Make sure to enclose them in paragraph tags.

\n
\n\n
\n

Prerequisites

\n

Add information about course prerequisites here.

\n
\n\n
\n

Course Staff

\n
\n
\n \"Course\n
\n\n

Staff Member #1

\n

Biography of instructor/staff member #1

\n
\n\n
\n
\n \"Course\n
\n\n

Staff Member #2

\n

Biography of instructor/staff member #2

\n
\n
\n\n
\n
\n

Frequently Asked Questions

\n
\n

Do I need to buy a textbook?

\n

No, a free online version of Chemistry: Principles, Patterns, and Applications, First Edition by Bruce Averill and Patricia Eldredge will be available, though you can purchase a printed version (published by FlatWorld Knowledge) if you’d like.

\n
\n\n
\n

Question #2

\n

Your answer would be displayed here.

\n
\n
\n
\n" - } - ) self.store.create_item( self.user.id, self.toy_loc, "course_info", "handouts", fields={"data": "Sample"} diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py index 3dc1c64b4b..598784b5df 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -348,7 +348,7 @@ class TestMixedModuleStore(unittest.TestCase): # split: 3 to get the course structure & the course definition (show_calculator is scope content) # before the change. 1 during change to refetch the definition. 3 afterward (b/c it calls get_item to return the "new" object). # 2 sends to update index & structure (calculator is a setting field) - @ddt.data(('draft', 7, 5), ('split', 7, 2)) + @ddt.data(('draft', 7, 5), ('split', 6, 2)) @ddt.unpack def test_update_item(self, default_ms, max_find, max_send): """ @@ -853,7 +853,6 @@ class TestMixedModuleStore(unittest.TestCase): # detached items (not considered as orphans) detached_locations = [ course_id.make_usage_key('static_tab', 'StaticTab'), - course_id.make_usage_key('about', 'overview'), course_id.make_usage_key('course_info', 'updates'), ]