Move about overview creation to common superclass

This commit is contained in:
Don Mitchell
2014-08-05 09:30:21 -04:00
parent 70c77f48b8
commit 5fc30dc4f6
6 changed files with 28 additions and 22 deletions

View File

@@ -588,6 +588,25 @@ class ModuleStoreWriteBase(ModuleStoreReadBase, ModuleStoreWrite):
result[field.scope][field_name] = value result[field.scope][field_name] = value
return result 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): 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 This base method just copies the assets. The lower level impls must do the actual cloning of

View File

@@ -29,7 +29,6 @@ from importlib import import_module
from xmodule.errortracker import null_error_tracker, exc_info_to_str from xmodule.errortracker import null_error_tracker, exc_info_to_str
from xmodule.mako_module import MakoDescriptorSystem from xmodule.mako_module import MakoDescriptorSystem
from xmodule.error_module import ErrorDescriptor from xmodule.error_module import ErrorDescriptor
from xmodule.html_module import AboutDescriptor
from xblock.runtime import KvsFieldData from xblock.runtime import KvsFieldData
from xblock.exceptions import InvalidScopeError from xblock.exceptions import InvalidScopeError
from xblock.fields import Scope, ScopeIds, Reference, ReferenceList, ReferenceValueDict from xblock.fields import Scope, ScopeIds, Reference, ReferenceList, ReferenceValueDict
@@ -948,22 +947,14 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
if courses.count() > 0: if courses.count() > 0:
raise DuplicateCourseError(course_id, courses[0]['_id']) 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 # create any other necessary things as a side effect
about_location = course_id.make_usage_key('about', 'overview') super(MongoModuleStore, self).create_course(
org, course, run, user_id, runtime=xblock.runtime, **kwargs
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
) )
return course return xblock
def create_xblock( def create_xblock(
self, runtime, course_key, block_type, block_id=None, fields=None, self, runtime, course_key, block_type, block_id=None, fields=None,

View File

@@ -1091,6 +1091,7 @@ class SplitMongoModuleStore(ModuleStoreWriteBase):
if fields is not None: if fields is not None:
self._update_search_targets(index_entry, fields) self._update_search_targets(index_entry, fields)
self.db_connection.insert_course_index(index_entry) self.db_connection.insert_course_index(index_entry)
# expensive hack to persist default field values set in __init__ method (e.g., wiki_slug) # expensive hack to persist default field values set in __init__ method (e.g., wiki_slug)
course = self.get_course(locator, **kwargs) course = self.get_course(locator, **kwargs)
return self.update_item(course, user_id, **kwargs) return self.update_item(course, user_id, **kwargs)

View File

@@ -86,6 +86,7 @@ class DraftVersioningModuleStore(ModuleStoreDraftAndPublished, SplitMongoModuleS
definition_locator=None, fields=None, definition_locator=None, fields=None,
force=False, continue_version=False, **kwargs force=False, continue_version=False, **kwargs
): ):
course_key = self._map_revision_to_branch(course_key)
item = super(DraftVersioningModuleStore, self).create_item( item = super(DraftVersioningModuleStore, self).create_item(
user_id, course_key, block_type, block_id=block_id, user_id, course_key, block_type, block_id=block_id,
definition_locator=definition_locator, fields=fields, 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, self, user_id, parent_usage_key, block_type, block_id=None,
fields=None, continue_version=False, **kwargs fields=None, continue_version=False, **kwargs
): ):
parent_usage_key = self._map_revision_to_branch(parent_usage_key)
item = super(DraftVersioningModuleStore, self).create_child( item = super(DraftVersioningModuleStore, self).create_child(
user_id, parent_usage_key, block_type, block_id=block_id, user_id, parent_usage_key, block_type, block_id=block_id,
fields=fields, continue_version=continue_version, **kwargs fields=fields, continue_version=continue_version, **kwargs

View File

@@ -348,12 +348,6 @@ class ModuleStoreTestCase(TestCase):
self.user.id, self.toy_loc, "about", block_id="end_date", self.user.id, self.toy_loc, "about", block_id="end_date",
fields={"data": "TBD"} fields={"data": "TBD"}
) )
self.store.create_item(
self.user.id, self.toy_loc, "about", block_id="overview",
fields={
"data": "<section class=\"about\">\n <h2>About This Course</h2>\n <p>Include your long course description here. The long course description should contain 150-400 words.</p>\n\n <p>This is paragraph 2 of the long course description. Add more paragraphs as needed. Make sure to enclose them in paragraph tags.</p>\n</section>\n\n<section class=\"prerequisites\">\n <h2>Prerequisites</h2>\n <p>Add information about course prerequisites here.</p>\n</section>\n\n<section class=\"course-staff\">\n <h2>Course Staff</h2>\n <article class=\"teacher\">\n <div class=\"teacher-image\">\n <img src=\"/static/images/pl-faculty.png\" align=\"left\" style=\"margin:0 20 px 0\" alt=\"Course Staff Image #1\">\n </div>\n\n <h3>Staff Member #1</h3>\n <p>Biography of instructor/staff member #1</p>\n </article>\n\n <article class=\"teacher\">\n <div class=\"teacher-image\">\n <img src=\"/static/images/pl-faculty.png\" align=\"left\" style=\"margin:0 20 px 0\" alt=\"Course Staff Image #2\">\n </div>\n\n <h3>Staff Member #2</h3>\n <p>Biography of instructor/staff member #2</p>\n </article>\n</section>\n\n<section class=\"faq\">\n <section class=\"responses\">\n <h2>Frequently Asked Questions</h2>\n <article class=\"response\">\n <h3>Do I need to buy a textbook?</h3>\n <p>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 youd like.</p>\n </article>\n\n <article class=\"response\">\n <h3>Question #2</h3>\n <p>Your answer would be displayed here.</p>\n </article>\n </section>\n</section>\n"
}
)
self.store.create_item( self.store.create_item(
self.user.id, self.toy_loc, "course_info", "handouts", self.user.id, self.toy_loc, "course_info", "handouts",
fields={"data": "<a href='/static/handouts/sample_handout.txt'>Sample</a>"} fields={"data": "<a href='/static/handouts/sample_handout.txt'>Sample</a>"}

View File

@@ -348,7 +348,7 @@ class TestMixedModuleStore(unittest.TestCase):
# split: 3 to get the course structure & the course definition (show_calculator is scope content) # 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). # 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) # 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 @ddt.unpack
def test_update_item(self, default_ms, max_find, max_send): 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 items (not considered as orphans)
detached_locations = [ detached_locations = [
course_id.make_usage_key('static_tab', 'StaticTab'), course_id.make_usage_key('static_tab', 'StaticTab'),
course_id.make_usage_key('about', 'overview'),
course_id.make_usage_key('course_info', 'updates'), course_id.make_usage_key('course_info', 'updates'),
] ]