Skip to content

Commit

Permalink
fix: update compat
Browse files Browse the repository at this point in the history
  • Loading branch information
CefBoud committed Feb 20, 2024
1 parent 55529e8 commit 27497c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
29 changes: 21 additions & 8 deletions section_to_course/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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(

Check warning on line 148 in section_to_course/compat.py

View check run for this annotation

Codecov / codecov/patch

section_to_course/compat.py#L148

Added line #L148 was not covered by tests
block_key.type, block_key.id,
)
return upstream_derive_key(usage_key, destination_course)

Check warning on line 151 in section_to_course/compat.py

View check run for this annotation

Codecov / codecov/patch

section_to_course/compat.py#L151

Added line #L151 was not covered by tests
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):
Expand Down
4 changes: 2 additions & 2 deletions section_to_course/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from section_to_course.compat import (
block_key_class,
derived_key,
derive_key,
duplicate_block,
modulestore,
not_found_exception,
Expand All @@ -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,
)
Expand Down

0 comments on commit 27497c1

Please sign in to comment.