diff --git a/section_to_course/compat.py b/section_to_course/compat.py index 50fe1e4..c2a205c 100644 --- a/section_to_course/compat.py +++ b/section_to_course/compat.py @@ -76,7 +76,11 @@ def block_key_class(): """ Get the BlockKey class from upstream. """ - from xmodule.modulestore.split_mongo import BlockKey + try: + # Quince and newer + from xmodule.util.keys import BlockKey + except ImportError: + from xmodule.modulestore.split_mongo import BlockKey return BlockKey @@ -134,16 +138,25 @@ def update_from_source( ) -def derived_key(destination_course_key, block_key, destination_course): +def derive_key(destination_course_key, block_key, destination_course): """ Get the derived ID for a block duplicated from a source block. See upstream function. """ - from xmodule.modulestore.store_utilities import derived_key as upstream_derived_key - return upstream_derived_key( - destination_course_key, - block_key, - destination_course, - ) + try: + # Quince and newer + from xmodule.util.keys import derive_key as upstream_derive_key + usage_key = destination_course_key.make_usage_key( + block_key.type, block_key.id, + ) + return upstream_derive_key(usage_key, destination_course) + except ImportError: + from xmodule.modulestore.store_utilities import derived_key as upstream_derive_key + + return upstream_derive_key( + destination_course_key, + block_key, + destination_course, + ) def get_course_outline(course_key: CourseLocator): diff --git a/section_to_course/utils.py b/section_to_course/utils.py index 2cc63e3..d1ff65a 100644 --- a/section_to_course/utils.py +++ b/section_to_course/utils.py @@ -6,7 +6,7 @@ from section_to_course.compat import ( block_key_class, - derived_key, + derive_key, duplicate_block, modulestore, not_found_exception, @@ -31,7 +31,7 @@ def paste_from_template(*, source_block_usage_key, destination_course_key, user) block_key = block_key_class()(source_block_usage_key.block_type, source_block_usage_key.block_id) block = store.get_item(source_block_usage_key) with store.bulk_operations(destination_course_key): - destination_key = derived_key(destination_course_key, block_key, destination_course) + destination_key = derive_key(destination_course_key, block_key, destination_course) destination_usage_key = destination_course_key.make_usage_key( destination_key.type, destination_key.id, )