Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update compat #54

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions section_to_course/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@
"""
Get the BlockKey class from upstream.
"""
from xmodule.modulestore.split_mongo import BlockKey
try:
# Releases newer than Quince
from xmodule.util.keys import BlockKey
except ImportError:
from xmodule.modulestore.split_mongo import BlockKey
return BlockKey


Expand Down Expand Up @@ -134,16 +138,24 @@
)


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:
# Releases newer than Quince
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
Loading