Unrelated: fix two bugs when duplicating a LibraryContentModule
This commit is contained in:
committed by
E. Kolpakov
parent
3857a1c1ee
commit
325c36069a
@@ -559,7 +559,10 @@ def _duplicate_item(parent_usage_key, duplicate_source_usage_key, user, display_
|
||||
category = dest_usage_key.block_type
|
||||
|
||||
# Update the display name to indicate this is a duplicate (unless display name provided).
|
||||
duplicate_metadata = own_metadata(source_item)
|
||||
duplicate_metadata = {} # Can't use own_metadata(), b/c it converts data for JSON serialization - not suitable for setting metadata of the new block
|
||||
for field in source_item.fields.values():
|
||||
if (field.scope == Scope.settings and field.is_set_on(source_item)):
|
||||
duplicate_metadata[field.name] = field.read_from(source_item)
|
||||
if display_name is not None:
|
||||
duplicate_metadata['display_name'] = display_name
|
||||
else:
|
||||
@@ -584,7 +587,8 @@ def _duplicate_item(parent_usage_key, duplicate_source_usage_key, user, display_
|
||||
dest_module.children = []
|
||||
for child in source_item.children:
|
||||
dupe = _duplicate_item(dest_module.location, child, user=user)
|
||||
dest_module.children.append(dupe)
|
||||
if dupe not in dest_module.children: # _duplicate_item may add the child for us.
|
||||
dest_module.children.append(dupe)
|
||||
store.update_item(dest_module, user.id)
|
||||
|
||||
if 'detached' not in source_item.runtime.load_block_type(category)._class_tags:
|
||||
|
||||
@@ -211,8 +211,8 @@ def inherit_metadata(descriptor, inherited_data):
|
||||
|
||||
def own_metadata(module):
|
||||
"""
|
||||
Return a dictionary that contains only non-inherited field keys,
|
||||
mapped to their serialized values
|
||||
Return a JSON-friendly dictionary that contains only non-inherited field
|
||||
keys, mapped to their serialized values
|
||||
"""
|
||||
return module.get_explicitly_set_fields_by_scope(Scope.settings)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user