Commit b9a7c7f7 by Don Mitchell

Create new structure allows override of usage id and category

parent 2c90dc73
......@@ -378,7 +378,7 @@ class SplitMongoModuleStore(ModuleStoreBase):
"""
return self.get_item(location, depth=depth)
def get_parent_locations(self, locator, usage_id=None):
def get_parent_locations(self, locator, course_id=None):
'''
Return the locations (Locators w/ usage_ids) for the parents of this location in this
course. Could use get_items(location, {'children': usage_id}) but this is slightly faster.
......@@ -387,7 +387,6 @@ class SplitMongoModuleStore(ModuleStoreBase):
:param locator: BlockUsageLocator restricting search scope
:param usage_id: ignored. Only included for API compatibility. Specify the usage_id within the locator.
'''
course = self._lookup_course(locator)
items = []
for parent_id, value in course['blocks'].iteritems():
......@@ -717,7 +716,9 @@ class SplitMongoModuleStore(ModuleStoreBase):
def create_course(
self, org, prettyid, user_id, id_root=None, fields=None,
master_branch='draft', versions_dict=None, root_category='course'):
master_branch='draft', versions_dict=None, root_category='course',
root_usage_id='course'
):
"""
Create a new entry in the active courses index which points to an existing or new structure. Returns
the course root of the resulting entry (the location has the course id)
......@@ -749,7 +750,7 @@ class SplitMongoModuleStore(ModuleStoreBase):
provide any fields overrides, see above). if not provided, will create a mostly empty course
structure with just a category course root xblock.
"""
partitioned_fields = self._partition_fields_by_scope('course', fields)
partitioned_fields = self._partition_fields_by_scope(root_category, fields)
block_fields = partitioned_fields.setdefault(Scope.settings, {})
if Scope.children in partitioned_fields:
block_fields.update(partitioned_fields[Scope.children])
......@@ -773,13 +774,13 @@ class SplitMongoModuleStore(ModuleStoreBase):
self.definitions.update({'_id': definition_id}, {'$set': {"edit_info.original_version": definition_id}})
draft_structure = {
'root': 'course',
'root': root_usage_id,
'previous_version': None,
'edited_by': user_id,
'edited_on': datetime.datetime.now(UTC),
'blocks': {
'course': {
'category': 'course',
root_usage_id: {
'category': root_category,
'definition': definition_id,
'fields': block_fields,
'edit_info': {
......@@ -794,7 +795,7 @@ class SplitMongoModuleStore(ModuleStoreBase):
draft_structure['original_version'] = new_id
self.structures.update({'_id': new_id},
{'$set': {"original_version": new_id,
'blocks.course.edit_info.update_version': new_id}})
'blocks.{}.edit_info.update_version'.format(root_usage_id): new_id}})
if versions_dict is None:
versions_dict = {master_branch: new_id}
else:
......
......@@ -17,6 +17,7 @@ from xmodule.modulestore.inheritance import InheritanceMixin
from pytz import UTC
from path import path
import re
import random
class SplitModuleTest(unittest.TestCase):
......@@ -250,7 +251,6 @@ class SplitModuleCourseTests(SplitModuleTest):
self.assertEqual(str(result.children[0].locator.version_guid), self.GUID_D1)
self.assertEqual(len(result.children[0].children), 1)
class SplitModuleItemTests(SplitModuleTest):
'''
Item read tests including inheritance
......@@ -967,6 +967,27 @@ class TestCourseCreation(SplitModuleTest):
course = modulestore().get_course(CourseLocator(course_id=locator.course_id, branch="published"))
self.assertEqual(str(course.location.version_guid), self.GUID_D1)
def test_create_with_root(self):
"""
Test create_course with a specified root id and category
"""
user = random.getrandbits(32)
new_course = modulestore().create_course(
'test_org', 'test_transaction', user,
root_usage_id='top', root_category='chapter'
)
self.assertEqual(new_course.location.usage_id, 'top')
self.assertEqual(new_course.category, 'chapter')
# look at db to verify
db_structure = modulestore().structures.find_one({
'_id': new_course.location.as_object_id(new_course.location.version_guid)
})
self.assertIsNotNone(db_structure, "Didn't find course")
self.assertNotIn('course', db_structure['blocks'])
self.assertIn('top', db_structure['blocks'])
self.assertEqual(db_structure['blocks']['top']['category'], 'chapter')
class TestInheritance(SplitModuleTest):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment