PLAT-1885 Stop using deprecated BlockUsageLocator properties

This commit is contained in:
Jeremy Bowman
2018-01-12 14:04:13 -05:00
parent c3abe79b09
commit 113e8dde61
51 changed files with 185 additions and 176 deletions

View File

@@ -15,7 +15,7 @@ def url_name_for_block(block):
block (XModuleMixin|CourseOverview|BlockStructureBlockData):
Block that is being accessed
"""
return block.location.name
return block.location.block_id
def display_name_with_default(block):

View File

@@ -117,7 +117,7 @@ class StaticContent(object):
the actual /c4x/... path which the client needs to reference static content
"""
if location is not None:
return u"/static/{name}".format(name=location.name)
return u"/static/{name}".format(name=location.block_id)
else:
return None
@@ -404,7 +404,7 @@ class ContentStore(object):
is_svg = content.content_type == 'image/svg+xml'
# use a naming convention to associate originals with the thumbnail
thumbnail_name = StaticContent.generate_thumbnail_name(
content.location.name, dimensions=dimensions, extension='.svg' if is_svg else None
content.location.block_id, dimensions=dimensions, extension='.svg' if is_svg else None
)
thumbnail_file_location = StaticContent.compute_location(
content.location.course_key, thumbnail_name, is_thumbnail=True

View File

@@ -196,7 +196,7 @@ class MongoContentStore(ContentStore):
self.export(asset['asset_key'], output_directory)
for attr, value in asset.iteritems():
if attr not in ['_id', 'md5', 'uploadDate', 'length', 'chunkSize', 'asset_key']:
policy.setdefault(asset['asset_key'].name, {})[attr] = value
policy.setdefault(asset['asset_key'].block_id, {})[attr] = value
with open(assets_policy_file, 'w') as f:
json.dump(policy, f, sort_keys=True, indent=4)
@@ -384,13 +384,22 @@ class MongoContentStore(ContentStore):
# stability of order is more important than sanity of order as any changes to order make things
# unfindable
ordered_key_fields = ['category', 'name', 'course', 'tag', 'org', 'revision']
property_names = {
'category': 'block_type',
'name': 'block_id',
'course': 'course',
'tag': 'DEPRECATED_TAG',
'org': 'org',
'revision': 'branch',
}
@classmethod
def asset_db_key(cls, location):
"""
Returns the database _id and son structured lookup to find the given asset location.
"""
dbkey = SON((field_name, getattr(location, field_name)) for field_name in cls.ordered_key_fields)
dbkey = SON((field_name,
getattr(location, cls.property_names[field_name])) for field_name in cls.ordered_key_fields)
if getattr(location, 'deprecated', False):
content_id = dbkey
else:

View File

@@ -99,7 +99,7 @@ class ErrorDescriptor(ErrorFields, XModuleDescriptor):
# access to the user context, and this will only be seen by staff
error_msg = 'Error not available'
if location.category == 'error':
if location.block_type == 'error':
location = location.replace(
# Pick a unique url_name -- the sha1 hash of the contents.
# NOTE: We could try to pull out the url_name of the errored descriptor,

View File

@@ -232,7 +232,7 @@ class HtmlDescriptor(HtmlBlock, XmlDescriptor, EditingDescriptor): # pylint: di
# (not same as 'html/blah.html' when the pointer is in a directory itself)
pointer_path = "{category}/{url_path}".format(
category='html',
url_path=name_to_pathname(location.name)
url_path=name_to_pathname(location.block_id)
)
base = path(pointer_path).dirname()
# log.debug("base = {0}, base.dirname={1}, filename={2}".format(base, base.dirname(), filename))

View File

@@ -326,7 +326,7 @@ class InheritingFieldData(KvsFieldData):
# from parent as '_copy_from_templates' puts fields into
# defaults.
if ancestor and \
ancestor.location.category == 'library_content' and \
ancestor.location.block_type == 'library_content' and \
self.has_default_value(name):
return super(InheritingFieldData, self).default(block, name)

View File

@@ -264,7 +264,7 @@ class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin):
if self.cached_metadata is not None:
# fish the parent out of here if it's available
parent_url = self.cached_metadata.get(unicode(location), {}).get('parent', {}).get(
ModuleStoreEnum.Branch.published_only if location.revision is None
ModuleStoreEnum.Branch.published_only if location.branch is None
else ModuleStoreEnum.Branch.draft_preferred
)
if parent_url:
@@ -274,7 +274,7 @@ class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin):
# try looking it up just-in-time (but not if we're working with a detached block).
parent = self.modulestore.get_parent_location(
as_published(location),
ModuleStoreEnum.RevisionOption.published_only if location.revision is None
ModuleStoreEnum.RevisionOption.published_only if location.branch is None
else ModuleStoreEnum.RevisionOption.draft_preferred
)
@@ -453,7 +453,7 @@ def as_draft(location):
Returns the Location that is the draft for `location`
If the location is in the DIRECT_ONLY_CATEGORIES, returns itself
"""
if location.category in DIRECT_ONLY_CATEGORIES:
if location.block_type in DIRECT_ONLY_CATEGORIES:
return location
return location.replace(revision=MongoRevisionKey.draft)
@@ -666,7 +666,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
"""
Returns the Location that is for the current branch setting.
"""
if location.category in DIRECT_ONLY_CATEGORIES:
if location.block_type in DIRECT_ONLY_CATEGORIES:
return location.replace(revision=MongoRevisionKey.published)
if self.get_branch_setting() == ModuleStoreEnum.Branch.draft_preferred:
return location.replace(revision=MongoRevisionKey.draft)
@@ -730,7 +730,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
results_by_url[location_url].setdefault('definition', {})['children'] = set(total_children)
else:
results_by_url[location_url] = result
if location.category == 'course':
if location.block_type == 'course':
root = location_url
# now traverse the tree and compute down the inherited metadata
@@ -1628,7 +1628,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
multi=False,
upsert=True,
)
elif ancestor_loc.category == 'course':
elif ancestor_loc.block_type == 'course':
# once we reach the top location of the tree and if the location is not an orphan then the
# parent is not an orphan either
non_orphan_parents.append(parent_loc)
@@ -1641,7 +1641,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
Helper for get_parent_location that finds the location that is the parent of this location in this course,
but does NOT return a version agnostic location.
'''
assert location.revision is None
assert location.branch is None
assert revision == ModuleStoreEnum.RevisionOption.published_only \
or revision == ModuleStoreEnum.RevisionOption.draft_preferred

View File

@@ -34,7 +34,7 @@ def wrap_draft(item):
Sets `item.is_draft` to `True` if the item is DRAFT, and `False` otherwise.
Sets the item's location to the non-draft location in either case.
"""
item.is_draft = (item.location.revision == MongoRevisionKey.draft)
item.is_draft = (item.location.branch == MongoRevisionKey.draft)
item.location = item.location.replace(revision=MongoRevisionKey.published)
return item
@@ -99,7 +99,7 @@ class DraftModuleStore(MongoModuleStore):
return get_published()
# if the item is direct-only, there can only be a published version
elif usage_key.category in DIRECT_ONLY_CATEGORIES:
elif usage_key.block_type in DIRECT_ONLY_CATEGORIES:
return get_published()
# return the draft version (without any fallback to PUBLISHED) if DRAFT-ONLY is requested
@@ -226,7 +226,7 @@ class DraftModuleStore(MongoModuleStore):
for module in modules:
original_loc = module.location
module.location = module.location.map_into_course(dest_course_id)
if module.location.category == 'course':
if module.location.block_type == 'course':
module.location = module.location.replace(name=module.location.run)
log.info("Cloning module %s to %s....", original_loc, module.location)
@@ -416,7 +416,7 @@ class DraftModuleStore(MongoModuleStore):
_verify_revision_is_published(location)
# ensure we are not creating a DRAFT of an item that is direct-only
if location.category in DIRECT_ONLY_CATEGORIES:
if location.block_type in DIRECT_ONLY_CATEGORIES:
raise InvalidVersionError(location)
def convert_item(item, to_be_deleted):
@@ -469,7 +469,7 @@ class DraftModuleStore(MongoModuleStore):
draft_loc = self.for_branch_setting(xblock.location)
# if the revision is published, defer to base
if draft_loc.revision == MongoRevisionKey.published:
if draft_loc.branch == MongoRevisionKey.published:
item = super(DraftModuleStore, self).update_item(xblock, user_id, allow_not_found)
course_key = xblock.location.course_key
if isPublish or (item.category in DIRECT_ONLY_CATEGORIES and not child_update):
@@ -517,7 +517,7 @@ class DraftModuleStore(MongoModuleStore):
self._verify_branch_setting(ModuleStoreEnum.Branch.draft_preferred)
_verify_revision_is_published(location)
is_item_direct_only = location.category in DIRECT_ONLY_CATEGORIES
is_item_direct_only = location.block_type in DIRECT_ONLY_CATEGORIES
if is_item_direct_only or revision == ModuleStoreEnum.RevisionOption.published_only:
parent_revision = MongoRevisionKey.published
elif revision == ModuleStoreEnum.RevisionOption.all:
@@ -542,7 +542,7 @@ class DraftModuleStore(MongoModuleStore):
for parent_location in parent_locations:
# don't remove from direct_only parent if other versions of this still exists (this code
# assumes that there's only one parent_location in this case)
if not is_item_direct_only and parent_location.category in DIRECT_ONLY_CATEGORIES:
if not is_item_direct_only and parent_location.block_type in DIRECT_ONLY_CATEGORIES:
# see if other version of to-be-deleted root exists
query = location.to_deprecated_son(prefix='_id.')
del query['_id.revision']
@@ -699,7 +699,7 @@ class DraftModuleStore(MongoModuleStore):
for child_loc in item.children:
_internal_depth_first(child_loc, False)
if item_location.category in DIRECT_ONLY_CATEGORIES or not getattr(item, 'is_draft', False):
if item_location.block_type in DIRECT_ONLY_CATEGORIES or not getattr(item, 'is_draft', False):
# ignore noop attempt to publish something that can't be or isn't currently draft
return
@@ -757,7 +757,7 @@ class DraftModuleStore(MongoModuleStore):
to remove things from the published version
"""
# ensure we are not creating a DRAFT of an item that is direct-only
if location.category in DIRECT_ONLY_CATEGORIES:
if location.block_type in DIRECT_ONLY_CATEGORIES:
raise InvalidVersionError(location)
self._verify_branch_setting(ModuleStoreEnum.Branch.draft_preferred)
@@ -779,7 +779,7 @@ class DraftModuleStore(MongoModuleStore):
self._verify_branch_setting(ModuleStoreEnum.Branch.draft_preferred)
_verify_revision_is_published(location)
if location.category in DIRECT_ONLY_CATEGORIES:
if location.block_type in DIRECT_ONLY_CATEGORIES:
return
if not self.has_item(location, revision=ModuleStoreEnum.RevisionOption.published_only):
@@ -855,7 +855,7 @@ class DraftModuleStore(MongoModuleStore):
query = []
for item in items:
item_usage_key = UsageKey.from_string(item).map_into_course(course_key)
if item_usage_key.category not in DIRECT_ONLY_CATEGORIES:
if item_usage_key.block_type not in DIRECT_ONLY_CATEGORIES:
query.append(as_draft(item_usage_key).to_deprecated_son())
if query:
query = {'_id': {'$in': query}}
@@ -907,4 +907,4 @@ def _verify_revision_is_published(location):
"""
Asserts that the revision set on the given location is MongoRevisionKey.published
"""
assert location.revision == MongoRevisionKey.published
assert location.branch == MongoRevisionKey.published

View File

@@ -88,9 +88,9 @@ def path_to_location(modulestore, usage_key, full_path=False):
n = len(path)
course_id = path[0].course_key
# pull out the location names
chapter = path[1].name if n > 1 else None
section = path[2].name if n > 2 else None
vertical = path[3].name if n > 3 else None
chapter = path[1].block_id if n > 1 else None
section = path[2].block_id if n > 2 else None
vertical = path[3].block_id if n > 3 else None
# Figure out the position
position = None

View File

@@ -169,8 +169,8 @@ class SplitMigrator(object):
continue
old_parent = self.source_modulestore.get_item(parent_loc, **kwargs)
split_parent_loc = new_draft_course_loc.make_usage_key(
parent_loc.category,
parent_loc.block_id if parent_loc.category != 'course' else published_course_usage_key.block_id
parent_loc.block_type,
parent_loc.block_id if parent_loc.block_type != 'course' else published_course_usage_key.block_id
)
new_parent = self.split_modulestore.get_item(split_parent_loc, **kwargs)
# this only occurs if the parent was also awaiting adoption: skip this one, go to next
@@ -202,8 +202,8 @@ class SplitMigrator(object):
Convert the location
"""
return new_course_key.make_usage_key(
location.category,
location.block_id if location.category != 'course' else course_block_id
location.block_type,
location.block_id if location.block_type != 'course' else course_block_id
)
result = {}

View File

@@ -39,7 +39,7 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
)
if master_branch == ModuleStoreEnum.BranchName.draft and not skip_auto_publish:
# any other value is hopefully only cloning or doing something which doesn't want this value add
self._auto_publish_no_children(item.location, item.location.category, user_id, **kwargs)
self._auto_publish_no_children(item.location, item.location.block_type, user_id, **kwargs)
# create any other necessary things as a side effect: ensure they populate the draft branch
# and rely on auto publish to populate the published branch: split's create course doesn't
@@ -130,7 +130,7 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
keys_to_check = list(new_keys)
while keys_to_check:
usage_key = keys_to_check.pop()
if usage_key.category in DIRECT_ONLY_CATEGORIES:
if usage_key.block_type in DIRECT_ONLY_CATEGORIES:
self.publish(usage_key.version_agnostic(), user_id, blacklist=EXCLUDE_ALL, **kwargs)
children = getattr(self.get_item(usage_key, **kwargs), "children", [])
# e.g. if usage_key is a chapter, it may have an auto-publish sequential child
@@ -152,7 +152,7 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
asides=asides,
**kwargs
)
self._auto_publish_no_children(item.location, item.location.category, user_id, **kwargs)
self._auto_publish_no_children(item.location, item.location.block_type, user_id, **kwargs)
descriptor.location = old_descriptor_locn
return item
@@ -171,7 +171,7 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
force=force, **kwargs
)
if not skip_auto_publish:
self._auto_publish_no_children(item.location, item.location.category, user_id, **kwargs)
self._auto_publish_no_children(item.location, item.location.block_type, user_id, **kwargs)
return item
def create_child(
@@ -185,8 +185,8 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
fields=fields, asides=asides, **kwargs
)
# Publish both the child and the parent, if the child is a direct-only category
self._auto_publish_no_children(item.location, item.location.category, user_id, **kwargs)
self._auto_publish_no_children(parent_usage_key, item.location.category, user_id, **kwargs)
self._auto_publish_no_children(item.location, item.location.block_type, user_id, **kwargs)
self._auto_publish_no_children(parent_usage_key, item.location.block_type, user_id, **kwargs)
return item
def delete_item(self, location, user_id, revision=None, skip_auto_publish=False, **kwargs):
@@ -215,7 +215,7 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
with self.bulk_operations(location.course_key):
if isinstance(location, LibraryUsageLocator):
branches_to_delete = [ModuleStoreEnum.BranchName.library] # Libraries don't yet have draft/publish support
elif location.category in DIRECT_ONLY_CATEGORIES:
elif location.block_type in DIRECT_ONLY_CATEGORIES:
branches_to_delete = [ModuleStoreEnum.BranchName.published, ModuleStoreEnum.BranchName.draft]
elif revision == ModuleStoreEnum.RevisionOption.all:
branches_to_delete = [ModuleStoreEnum.BranchName.published, ModuleStoreEnum.BranchName.draft]
@@ -408,7 +408,7 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
:raises InvalidVersionError: if no published version exists for the location specified
"""
if location.category in DIRECT_ONLY_CATEGORIES:
if location.block_type in DIRECT_ONLY_CATEGORIES:
return
draft_course_key = location.course_key.for_branch(ModuleStoreEnum.BranchName.draft)

View File

@@ -402,7 +402,7 @@ class ItemFactory(XModuleFactory):
course = store.get_course(location.course_key)
course.tabs.append(
CourseTab.load('static_tab', name='Static Tab', url_slug=location.name)
CourseTab.load('static_tab', name='Static Tab', url_slug=location.block_id)
)
store.update_item(course, user_id)

View File

@@ -155,7 +155,7 @@ class TestContentstore(unittest.TestCase):
self.assertEqual(count, len(self.course1_files), course1_assets)
for asset in course1_assets:
parsed = AssetKey.from_string(asset['filename'])
self.assertIn(parsed.name, self.course1_files)
self.assertIn(parsed.block_id, self.course1_files)
course1_assets, __ = self.contentstore.get_all_content_for_course(self.course1_key, 1, 1)
self.assertEqual(len(course1_assets), 1, course1_assets)

View File

@@ -715,7 +715,7 @@ class TestMongoModuleStore(TestMongoModuleStoreBase):
course_key = CourseLocator(org="edX", course="101", run="2015")
root_block_key = self.draft_store.make_course_usage_key(course_key)
self.assertEqual(root_block_key.block_type, "course")
self.assertEqual(root_block_key.name, "2015")
self.assertEqual(root_block_key.block_id, "2015")
class TestMongoModuleStoreWithNoAssetCollection(TestMongoModuleStore):

View File

@@ -38,7 +38,7 @@ class TestMigration(SplitWMongoCourseBootstrapper):
self._create_item('chapter', chapter1_name, {}, {'display_name': 'Chapter 1'}, 'course', 'runid', split=False)
chap2_loc = self.old_course_key.make_usage_key('chapter', uuid.uuid4().hex)
self._create_item(
chap2_loc.category, chap2_loc.name, {}, {'display_name': 'Chapter 2'}, 'course', 'runid', split=False
chap2_loc.block_type, chap2_loc.block_id, {}, {'display_name': 'Chapter 2'}, 'course', 'runid', split=False
)
# vertical in live only
live_vert_name = uuid.uuid4().hex
@@ -50,7 +50,7 @@ class TestMigration(SplitWMongoCourseBootstrapper):
# vertical in both live and draft
both_vert_loc = self.old_course_key.make_usage_key('vertical', uuid.uuid4().hex)
self._create_item(
both_vert_loc.category, both_vert_loc.name, {}, {'display_name': 'Both vertical'}, 'chapter', chapter1_name,
both_vert_loc.block_type, both_vert_loc.block_id, {}, {'display_name': 'Both vertical'}, 'chapter', chapter1_name,
draft=False, split=False
)
self.create_random_units(False, both_vert_loc)
@@ -61,13 +61,13 @@ class TestMigration(SplitWMongoCourseBootstrapper):
# vertical in draft only (x2)
draft_vert_loc = self.old_course_key.make_usage_key('vertical', uuid.uuid4().hex)
self._create_item(
draft_vert_loc.category, draft_vert_loc.name, {}, {'display_name': 'Draft vertical'}, 'chapter', chapter1_name,
draft_vert_loc.block_type, draft_vert_loc.block_id, {}, {'display_name': 'Draft vertical'}, 'chapter', chapter1_name,
draft=True, split=False
)
self.create_random_units(True, draft_vert_loc)
draft_vert_loc = self.old_course_key.make_usage_key('vertical', uuid.uuid4().hex)
self._create_item(
draft_vert_loc.category, draft_vert_loc.name, {}, {'display_name': 'Draft vertical2'}, 'chapter', chapter1_name,
draft_vert_loc.block_type, draft_vert_loc.block_id, {}, {'display_name': 'Draft vertical2'}, 'chapter', chapter1_name,
draft=True, split=False
)
self.create_random_units(True, draft_vert_loc)
@@ -75,7 +75,7 @@ class TestMigration(SplitWMongoCourseBootstrapper):
# and finally one in live only (so published has to skip 2 preceding sibs)
live_vert_loc = self.old_course_key.make_usage_key('vertical', uuid.uuid4().hex)
self._create_item(
live_vert_loc.category, live_vert_loc.name, {}, {'display_name': 'Live vertical end'}, 'chapter', chapter1_name,
live_vert_loc.block_type, live_vert_loc.block_id, {}, {'display_name': 'Live vertical end'}, 'chapter', chapter1_name,
draft=False, split=False
)
self.create_random_units(False, live_vert_loc)
@@ -86,7 +86,7 @@ class TestMigration(SplitWMongoCourseBootstrapper):
indirect2_loc = self.old_course_key.make_usage_key('html', uuid.uuid4().hex)
conditional_loc = self.old_course_key.make_usage_key('conditional', uuid.uuid4().hex)
self._create_item(
conditional_loc.category, conditional_loc.name,
conditional_loc.block_type, conditional_loc.block_id,
{
'show_tag_list': [indirect1_loc, indirect2_loc],
'sources_list': [live_vert_loc, ],
@@ -96,18 +96,18 @@ class TestMigration(SplitWMongoCourseBootstrapper):
'completed': True,
},
},
chap2_loc.category, chap2_loc.name,
chap2_loc.block_type, chap2_loc.block_id,
draft=False, split=False
)
# create the children
self._create_item(
indirect1_loc.category, indirect1_loc.name, {'data': ""}, {'display_name': 'conditional show 1'},
conditional_loc.category, conditional_loc.name,
indirect1_loc.block_type, indirect1_loc.block_id, {'data': ""}, {'display_name': 'conditional show 1'},
conditional_loc.block_type, conditional_loc.block_id,
draft=False, split=False
)
self._create_item(
indirect2_loc.category, indirect2_loc.name, {'data': ""}, {'display_name': 'conditional show 2'},
conditional_loc.category, conditional_loc.name,
indirect2_loc.block_type, indirect2_loc.block_id, {'data': ""}, {'display_name': 'conditional show 2'},
conditional_loc.block_type, conditional_loc.block_id,
draft=False, split=False
)
@@ -143,7 +143,7 @@ class TestMigration(SplitWMongoCourseBootstrapper):
metadata = {'display_name': str(uuid.uuid4()), 'graded': True}
data = {}
self._create_item(
location.category, location.name, data, metadata, parent_loc.category, parent_loc.name,
location.block_type, location.block_id, data, metadata, parent_loc.block_type, parent_loc.block_id,
draft=draft, split=False
)

View File

@@ -932,7 +932,7 @@ class SplitModuleCourseTests(SplitModuleTest):
root_block_key = modulestore().make_course_usage_key(course_key)
self.assertIsInstance(root_block_key, root_block_cls)
self.assertEqual(root_block_key.block_type, "course")
self.assertEqual(root_block_key.name, "course")
self.assertEqual(root_block_key.block_id, "course")
class TestCourseStructureCache(SplitModuleTest):

View File

@@ -280,7 +280,7 @@ class CourseExportManager(ExportManager):
# export all of the course metadata in policy.json
with course_run_policy_dir.open(u'policy.json', 'wb') as course_policy:
policy = {'course/' + courselike.location.name: own_metadata(courselike)}
policy = {'course/' + courselike.location.block_id: own_metadata(courselike)}
course_policy.write(dumps(policy, cls=EdxJSONEncoder, sort_keys=True, indent=4).encode('utf-8'))
_export_drafts(self.modulestore, self.courselike_key, export_fs, xml_centric_courselike_key)
@@ -389,7 +389,7 @@ def _export_field_content(xblock_item, item_dir):
for field_name in module_data:
if field_name not in DEFAULT_CONTENT_FIELDS:
# filename format: {dirname}.{field_name}.json
with item_dir.open(u'{0}.{1}.{2}'.format(xblock_item.location.name, field_name, 'json'),
with item_dir.open(u'{0}.{1}.{2}'.format(xblock_item.location.block_id, field_name, 'json'),
'wb') as field_content_file:
field_content_file.write(dumps(module_data.get(field_name, {}), cls=EdxJSONEncoder,
sort_keys=True, indent=4).encode('utf-8'))
@@ -402,7 +402,7 @@ def export_extra_content(export_fs, modulestore, source_course_key, dest_course_
item_dir = export_fs.makedir(dirname, recreate=True)
for item in items:
adapt_references(item, dest_course_key, export_fs)
with item_dir.open(item.location.name + file_suffix, 'wb') as item_file:
with item_dir.open(item.location.block_id + file_suffix, 'wb') as item_file:
item_file.write(item.data.encode('utf8'))
# export content fields other then metadata and data in json format in current directory

View File

@@ -741,7 +741,7 @@ def _update_and_import_module(
asides = module.get_asides() if isinstance(module, XModuleMixin) else None
block = store.import_xblock(
user_id, dest_course_id, module.location.category,
user_id, dest_course_id, module.location.block_type,
module.location.block_id, fields, runtime, asides=asides
)
@@ -749,7 +749,7 @@ def _update_and_import_module(
# Get to the point where XML import is happening inside the
# modulestore that is eventually going to store the data.
# Ticket: https://openedx.atlassian.net/browse/PLAT-1046
if block.location.category == 'library_content':
if block.location.block_type == 'library_content':
# if library exists, update source_library_version and children
# according to this existing library and library content block.
if store.get_library(block.source_library_key):
@@ -919,7 +919,7 @@ def check_module_metadata_editability(module):
we can't support editing. However we always allow 'display_name'
and 'xml_attributes'
"""
allowed = allowed_metadata_by_category(module.location.category)
allowed = allowed_metadata_by_category(module.location.block_type)
if '*' in allowed:
# everything is allowed
return 0
@@ -994,7 +994,7 @@ def validate_no_non_editable_metadata(module_store, course_id, category):
err_cnt = 0
for module_loc in module_store.modules[course_id]:
module = module_store.modules[course_id][module_loc]
if module.location.category == category:
if module.location.block_type == category:
err_cnt = err_cnt + check_module_metadata_editability(module)
return err_cnt
@@ -1007,19 +1007,19 @@ def validate_category_hierarchy(
parents = []
# get all modules of parent_category
for module in module_store.modules[course_id].itervalues():
if module.location.category == parent_category:
if module.location.block_type == parent_category:
parents.append(module)
for parent in parents:
for child_loc in parent.children:
if child_loc.category != expected_child_category:
if child_loc.block_type != expected_child_category:
err_cnt += 1
print(
"ERROR: child {child} of parent {parent} was expected to be "
"category of {expected} but was {actual}".format(
child=child_loc, parent=parent.location,
expected=expected_child_category,
actual=child_loc.category
actual=child_loc.block_type
)
)
@@ -1063,7 +1063,7 @@ def validate_course_policy(module_store, course_id):
# is there a reliable way to get the module location just given the course_id?
warn_cnt = 0
for module in module_store.modules[course_id].itervalues():
if module.location.category == 'course':
if module.location.block_type == 'course':
if not module._field_data.has(module, 'rerandomize'):
warn_cnt += 1
print(

View File

@@ -121,7 +121,7 @@ class PollModule(PollFields, XModule):
"""Renders parameters to template."""
params = {
'element_id': self.location.html_id(),
'element_class': self.location.category,
'element_class': self.location.block_type,
'ajax_url': self.system.ajax_url,
'configuration_json': self.dump_poll(),
}

View File

@@ -314,7 +314,7 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule):
'element_id': self.location.html_id(),
'item_id': text_type(self.location),
'position': self.position,
'tag': self.location.category,
'tag': self.location.block_type,
'ajax_url': self.system.ajax_url,
'next_url': context.get('next_url'),
'prev_url': context.get('prev_url'),

View File

@@ -549,11 +549,11 @@ class CourseComparisonTest(BulkAssertionTest):
actual_item_location = actual_course_key.make_usage_key(expected_item.category, expected_item.location.block_id)
# split and old mongo use different names for the course root but we don't know which
# modulestore actual's come from here; so, assume old mongo and if that fails, assume split
if expected_item.location.category == 'course':
if expected_item.location.block_type == 'course':
actual_item_location = actual_item_location.replace(name=actual_item_location.run)
actual_item = actual_item_map.get(map_key(actual_item_location))
# must be split
if actual_item is None and expected_item.location.category == 'course':
if actual_item is None and expected_item.location.block_type == 'course':
actual_item_location = actual_item_location.replace(name='course')
actual_item = actual_item_map.get(map_key(actual_item_location))

View File

@@ -127,8 +127,8 @@ class CourseMetadataUtilsTestCase(TestCase):
),
]),
FunctionTest(url_name_for_block, [
TestScenario((self.demo_course,), self.demo_course.location.name),
TestScenario((self.html_course,), self.html_course.location.name),
TestScenario((self.demo_course,), self.demo_course.location.block_id),
TestScenario((self.html_course,), self.html_course.location.block_id),
]),
FunctionTest(display_name_with_default_escaped, [
# Test course with no display name.

View File

@@ -132,7 +132,7 @@ class SequenceBlockTestCase(XModuleXmlImportTest):
def test_tooltip(self):
html = self._get_rendered_student_view(self.sequence_3_1, requested_child=None)
for child in self.sequence_3_1.children:
self.assertIn("'page_title': '{}'".format(child.name), html)
self.assertIn("'page_title': '{}'".format(child.block_id), html)
def test_hidden_content_before_due(self):
html = self._get_rendered_student_view(self.sequence_4_1)

View File

@@ -244,7 +244,7 @@ class WordCloudModule(WordCloudFields, XModule):
'ajax_url': self.system.ajax_url,
'display_name': self.display_name,
'instructions': self.instructions,
'element_class': self.location.category,
'element_class': self.location.block_type,
'element_id': self.location.html_id(),
'num_inputs': self.num_inputs,
'submitted': self.submitted,

View File

@@ -936,7 +936,7 @@ def policy_key(location):
Get the key for a location in a policy file. (Since the policy file is
specific to a course, it doesn't need the full location url).
"""
return u'{cat}/{name}'.format(cat=location.category, name=location.name)
return u'{cat}/{name}'.format(cat=location.block_type, name=location.block_id)
Template = namedtuple("Template", "metadata data children")