Skip to content
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
21 changes: 4 additions & 17 deletions xblocks_contrib/annotatable/annotatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import markupsafe
from django.utils.translation import gettext_noop as _
from lxml import etree
from opaque_keys.edx.keys import UsageKey
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.fields import Scope, String, XMLString
Expand Down Expand Up @@ -96,18 +95,6 @@ class AnnotatableBlock(LegacyXmlMixin, XBlock):
# List of supported highlight colors for annotations
HIGHLIGHT_COLORS = ["yellow", "orange", "purple", "blue", "green"]

@property
def location(self):
return self.scope_ids.usage_id

@location.setter
def location(self, value):
assert isinstance(value, UsageKey)
self.scope_ids = self.scope_ids._replace(
def_id=value, # Note: assigning a UsageKey as def_id is OK in old mongo / import system but wrong in split
usage_id=value,
)

def _get_annotation_class_attr(self, index, el): # pylint: disable=unused-argument
"""Returns a dict with the CSS class attribute to set on the annotation
and an XML key to delete from the element.
Expand Down Expand Up @@ -279,8 +266,8 @@ def definition_to_xml(self, resource_fs):
if not self.data:
log.warning(
"Could not serialize %s: No XBlock installed for '%s' tag.",
self.location,
self.location.block_type,
self.usage_key,
self.usage_key.block_type,
)
return None

Expand All @@ -297,6 +284,6 @@ def definition_to_xml(self, resource_fs):
"Context: '{context}'"
).format(
context=lines[line - 1][offset - 40:offset + 40],
loc=self.location,
loc=self.usage_key,
)
raise SerializationError(self.location, msg) from err
raise SerializationError(self.usage_key, msg) from err
2 changes: 1 addition & 1 deletion xblocks_contrib/annotatable/tests/test_annotatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AnnotatableBlockTestCase(unittest.TestCase):
def setUp(self):
super().setUp()
runtime = TestRuntime()
scope_ids = ScopeIds("user_id", "block_type", "block_id", "course_id")
scope_ids = ScopeIds("user_id", "block_type", "block_id", "context_key")
field_data = DictFieldData({"data": self.sample_xml})
self.annotatable = AnnotatableBlock(runtime, field_data, scope_ids)

Expand Down
30 changes: 5 additions & 25 deletions xblocks_contrib/html/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from django.utils.translation import gettext_noop as _
from fs.errors import ResourceNotFound
from lxml import etree
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import LibraryLocatorV2
from path import Path as path
from web_fragments.fragment import Fragment
Expand Down Expand Up @@ -187,26 +187,6 @@ class HtmlBlockMixin(LegacyXmlMixin, XBlock):
show_in_read_only_mode = True
icon_class = "other"

@property
def category(self):
return self.scope_ids.block_type

@property
def location(self):
return self.scope_ids.usage_id

@location.setter
def location(self, value):
assert isinstance(value, UsageKey)
self.scope_ids = self.scope_ids._replace(
def_id=value, # Note: assigning a UsageKey as def_id is OK in old mongo / import system but wrong in split
usage_id=value,
)

@property
def url_name(self):
return self.location.block_id

@property
def xblock_kvs(self):
"""
Expand Down Expand Up @@ -264,7 +244,7 @@ def get_html(self):
data = data.replace("%%USER_EMAIL%%", email)

# The course ID replacement is always safe to run.
data = data.replace("%%COURSE_ID%%", str(self.scope_ids.usage_id.context_key))
data = data.replace("%%COURSE_ID%%", str(self.context_key))
return data

def studio_view(self, context=None):
Expand Down Expand Up @@ -324,7 +304,7 @@ def get_context(self):
"module": self,
"editable_metadata_fields": self.editable_metadata_fields,
"data": self.data,
"base_asset_url": self.get_base_url_path_for_course_assets(self.location.course_key),
"base_asset_url": self.get_base_url_path_for_course_assets(self.context_key),
"enable_latex_compiler": self.use_latex_compiler,
"editor": self.editor,
}
Expand Down Expand Up @@ -545,8 +525,8 @@ def definition_to_xml(self, resource_fs):
"""

# Write html to file, return an empty tag
pathname = name_to_pathname(self.url_name)
filepath = "{category}/{pathname}.html".format(category=self.category, pathname=pathname)
pathname = name_to_pathname(self.usage_key.block_id)
filepath = "{category}/{pathname}.html".format(category=self.usage_key.block_type, pathname=pathname)

resource_fs.makedirs(os.path.dirname(filepath), recreate=True)
with resource_fs.open(filepath, "wb") as filestream:
Expand Down
2 changes: 1 addition & 1 deletion xblocks_contrib/problem/capa/responsetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def make_hint_div( # pylint: disable=too-many-positional-arguments,too-many-arg

# This is the "feedback hint" event
event_info = {}
event_info["module_id"] = str(self.capa_block.location)
event_info["module_id"] = str(self.capa_block.usage_key)
event_info["problem_part_id"] = self.id
event_info["trigger_type"] = "single" # maybe be overwritten by log_extra
event_info["hint_label"] = label
Expand Down
2 changes: 1 addition & 1 deletion xblocks_contrib/problem/capa/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def mock_location_text(self): # pylint: disable=unused-argument
return "i4x://Foo/bar/mock/abc"

capa_block = Mock()
capa_block.location.__str__ = mock_location_text
capa_block.usage_key.__str__ = mock_location_text
# The following comes into existence by virtue of being called
# capa_block.runtime.publish
return capa_block
Expand Down
2 changes: 2 additions & 0 deletions xblocks_contrib/problem/capa/tests/test_xqueue_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def xqueue_service():
"""
location = BlockUsageLocator(CourseLocator("test_org", "test_course", "test_run"), "problem", "ExampleProblem")
block = Mock(scope_ids=ScopeIds("user1", "problem", location, location))
block.usage_key = location
block.context_key = location.course_key
block.max_score = Mock(return_value=10)
return XQueueInterfaceSubmission(block)

Expand Down
2 changes: 1 addition & 1 deletion xblocks_contrib/problem/capa/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def get_course_id_from_capa_block(capa_block):
if not capa_block:
return None
try:
return str(capa_block.scope_ids.usage_id.course_key)
return str(capa_block.context_key)
except (AttributeError, TypeError):
# AttributeError:
# If the capa block lacks scope ids or has unexpected scope ids, we
Expand Down
4 changes: 2 additions & 2 deletions xblocks_contrib/problem/capa/xqueue_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def get_submission_params(self, header, payload):
if not self.block:
raise GetSubmissionParamsError()

course_id = str(self.block.scope_ids.usage_id.context_key)
course_id = str(self.block.context_key)
item_type = self.block.scope_ids.block_type
points_possible = self.block.max_score()

item_id = str(self.block.scope_ids.usage_id)
item_id = str(self.block.usage_key)

try:
grader_payload = self._parse_json(payload["grader_payload"], "grader_payload")
Expand Down
Loading
Loading