Skip to content

Commit 917a512

Browse files
authored
Merge pull request #204 from openedx/farhan/remove-legacy-attribs
Remove XModuleMixin legacy attibs from wordcloud, video block, lti block
2 parents efecf28 + d4920b3 commit 917a512

File tree

10 files changed

+111
-197
lines changed

10 files changed

+111
-197
lines changed

xblocks_contrib/common/xml_utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def own_metadata(block: XBlock) -> dict[str, Any]:
139139
except TypeError as exception:
140140
exception_message = "{message}, Block-location:{location}, Field-name:{field_name}".format(
141141
message=str(exception),
142-
location=str(block.location),
142+
location=str(block.usage_key),
143143
field_name=field.name
144144
)
145145
raise TypeError(exception_message) # lint-amnesty, pylint: disable=raise-missing-from
@@ -486,12 +486,12 @@ def add_xml_to_node(self, node):
486486
aside.add_xml_to_node(aside_node)
487487
xml_object.append(aside_node)
488488

489-
not_to_clean_fields = self.metadata_to_not_to_clean.get(self.category, ())
489+
not_to_clean_fields = self.metadata_to_not_to_clean.get(self.usage_key.block_type, ())
490490
self.clean_metadata_from_xml(xml_object, excluded_fields=not_to_clean_fields)
491491

492492
# Set the tag on both nodes so we get the file path right.
493-
xml_object.tag = self.category
494-
node.tag = self.category
493+
xml_object.tag = self.usage_key.block_type
494+
node.tag = self.usage_key.block_type
495495

496496
# Add the non-inherited metadata
497497
for attr in sorted(own_metadata(self)):
@@ -506,7 +506,7 @@ def add_xml_to_node(self, node):
506506
logging.exception(
507507
'Failed to serialize metadata attribute %s with value %s in module %s. '
508508
'This could mean data loss!!!',
509-
attr, val, self.url_name
509+
attr, val, self.usage_key.block_id
510510
)
511511

512512
for key, value in self.xml_attributes.items():
@@ -515,8 +515,8 @@ def add_xml_to_node(self, node):
515515

516516
if self.export_to_file():
517517
# Write the definition to a file
518-
url_path = name_to_pathname(self.url_name)
519-
filepath = self._format_filepath(self.category, url_path)
518+
url_path = name_to_pathname(self.usage_key.block_id)
519+
filepath = self._format_filepath(self.usage_key.block_type, url_path)
520520
self.runtime.export_fs.makedirs(os.path.dirname(filepath), recreate=True)
521521
with self.runtime.export_fs.open(filepath, 'wb') as fileobj:
522522
ElementTree(xml_object).write(fileobj, pretty_print=True, encoding='utf-8')
@@ -531,16 +531,16 @@ def add_xml_to_node(self, node):
531531

532532
# Do not override an existing value for the course.
533533
if not node.get('url_name'):
534-
node.set('url_name', self.url_name)
534+
node.set('url_name', self.usage_key.block_id)
535535

536536
# We do not need to cater the `course` category here in xblocks_contrib,
537537
# because course export is handled in the edx-platform code.
538538

539539
# Special case for course pointers:
540-
# if self.category == 'course':
540+
# if self.usage_key.block_type == 'course':
541541
# # add org and course attributes on the pointer tag
542-
# node.set('org', self.location.org)
543-
# node.set('course', self.location.course)
542+
# node.set('org', self.usage_key.org)
543+
# node.set('course', self.usage_key.course)
544544

545545
def definition_to_xml(self, resource_fs):
546546
"""

xblocks_contrib/discussion/discussion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def add_resource_urls(self, fragment):
150150
fragment.add_css_url(self.runtime.local_resource_url(self, f"{base_path}{css_file_path}"))
151151
fragment.add_javascript_url(self.runtime.local_resource_url(self, f"{base_path}/js/discussion_bundle.js"))
152152

153-
def has_permission(self, permission): # pylint: disable=unused-argument
153+
def has_permission(self, permission):
154154
"""
155155
Encapsulates lms specific functionality, as `has_permission` is not
156156
importable outside of lms context, namely in tests.

xblocks_contrib/lti/lti.py

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
from django.utils.translation import gettext_noop as _
7171
from lxml import etree
7272
from oauthlib.oauth1.rfc5849 import signature
73-
from opaque_keys.edx.keys import CourseKey, UsageKey
73+
from opaque_keys.edx.keys import CourseKey
7474
from pytz import UTC
7575
from web_fragments.fragment import Fragment
7676
from webob import Response
@@ -378,27 +378,6 @@ class LTIBlock(
378378
# Indicates that this XBlock has been extracted from edx-platform.
379379
is_extracted = True
380380

381-
@property
382-
def category(self):
383-
"""Return the block type/category."""
384-
return self.scope_ids.block_type
385-
386-
@property
387-
def url_name(self):
388-
return self.location.block_id
389-
390-
@property
391-
def location(self):
392-
return self.scope_ids.usage_id
393-
394-
@location.setter
395-
def location(self, value):
396-
assert isinstance(value, UsageKey)
397-
self.scope_ids = self.scope_ids._replace(
398-
def_id=value, # Note: assigning a UsageKey as def_id is OK in old mongo / import system but wrong in split
399-
usage_id=value,
400-
)
401-
402381
def max_score(self):
403382
return self.weight if self.has_score else None
404383

@@ -513,7 +492,7 @@ def get_context(self):
513492

514493
# These parameters do not participate in OAuth signing.
515494
'launch_url': self.launch_url.strip(),
516-
'element_id': self.location.html_id(),
495+
'element_id': self.usage_key.html_id(),
517496
'element_class': self.scope_ids.block_type,
518497
'open_in_a_new_page': self.open_in_a_new_page,
519498
'display_name': self.display_name,
@@ -747,7 +726,7 @@ def get_resource_link_id(self):
747726
i4x-2-3-lti-31de800015cf4afb973356dbe81496df this part of resource_link_id:
748727
makes resource_link_id to be unique among courses inside same system.
749728
"""
750-
return str(parse.quote(f"{settings.LMS_BASE}-{self.location.html_id()}"))
729+
return str(parse.quote(f"{settings.LMS_BASE}-{self.usage_key.html_id()}"))
751730

752731
def get_lis_result_sourcedid(self):
753732
"""
@@ -773,8 +752,8 @@ def get_course(self):
773752
In general, please do not add new code that access Modulestore, because it
774753
will not work with openedx_content. We do it here just to support a legacy feature.
775754
"""
776-
if isinstance(self.location.course_key, CourseKey):
777-
return self.runtime.modulestore.get_course(self.location.course_key)
755+
if isinstance(self.context_key, CourseKey):
756+
return self.runtime.modulestore.get_course(self.context_key)
778757
return None
779758

780759
@property
@@ -785,7 +764,7 @@ def context_id(self):
785764
context_id is an opaque identifier that uniquely identifies the context (e.g., a course)
786765
that contains the link being launched.
787766
"""
788-
return str(self.location.course_key)
767+
return str(self.context_key)
789768

790769
@property
791770
def role(self):
@@ -882,8 +861,8 @@ def oauth_params(self, custom_parameters, client_key, client_secret):
882861
# Stubbing headers for now:
883862
log.info(
884863
"LTI block %s in course %s does not have oauth parameters correctly configured.",
885-
self.location,
886-
self.location.course_key,
864+
self.usage_key,
865+
self.context_key,
887866
)
888867
headers = {
889868
'Content-Type': 'application/x-www-form-urlencoded',
@@ -1037,7 +1016,7 @@ def definition_from_xml(cls, xml_object, system):
10371016
def definition_to_xml(self, resource_fs):
10381017
if self.data:
10391018
return etree.fromstring(self.data)
1040-
return etree.Element(self.category)
1019+
return etree.Element(self.usage_key.block_type)
10411020

10421021
def bind_for_student(self, user_id, wrappers=None):
10431022
"""

xblocks_contrib/lti/tests/test_lti_unit.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def setUp(self):
5959
</imsx_POXBody>
6060
</imsx_POXEnvelopeRequest>
6161
""")
62-
self.course_id = CourseKey.from_string('org/course/run')
62+
self.context_key = CourseKey.from_string('org/course/run')
6363
self.runtime = get_test_system()
6464
self.runtime.publish = Mock()
6565
self.runtime._services['rebind_user'] = Mock() # pylint: disable=protected-access
@@ -68,7 +68,7 @@ def setUp(self):
6868
self.runtime,
6969
DictFieldData({}),
7070
ScopeIds(
71-
None, None, None, BlockUsageLocator(self.course_id, "lti", "name")
71+
None, None, None, BlockUsageLocator(self.context_key, "lti", "name")
7272
),
7373
)
7474
current_user = self.runtime.service(self.xblock, "user").get_current_user()
@@ -326,9 +326,9 @@ def mock_handler_url(
326326

327327
def test_resource_link_id(self):
328328
with patch(
329-
"xblocks_contrib.lti.lti.LTIBlock.location", new_callable=PropertyMock
329+
"xblocks_contrib.lti.lti.LTIBlock.usage_key", new_callable=PropertyMock
330330
):
331-
self.xblock.location.html_id = (
331+
self.xblock.usage_key.html_id = (
332332
lambda: "i4x-2-3-lti-31de800015cf4afb973356dbe81496df"
333333
)
334334
expected_resource_link_id = str(parse.quote(self.unquoted_resource_link_id))
@@ -339,7 +339,7 @@ def test_lis_result_sourcedid(self):
339339
expected_sourced_id = ":".join(
340340
parse.quote(i)
341341
for i in (
342-
str(self.course_id),
342+
str(self.context_key),
343343
self.xblock.get_resource_link_id(),
344344
self.user_id,
345345
)
@@ -576,4 +576,4 @@ def test_context_id(self):
576576
"""
577577
Tests that LTI parameter context_id is equal to course_id.
578578
"""
579-
assert str(self.course_id) == self.xblock.context_id
579+
assert str(self.context_key) == self.xblock.context_id

xblocks_contrib/video/content.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

xblocks_contrib/video/tests/test_video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ def test_export_to_xml(self, mock_get_edxval_api):
765765
video_id=edx_video_id,
766766
static_dir=EXPORT_IMPORT_STATIC_DIR,
767767
resource_fs=self.file_system,
768-
course_id=self.block.scope_ids.usage_id.context_key,
768+
course_id=self.block.context_key,
769769
)
770770

771771
def test_export_to_xml_without_video_id(self):

0 commit comments

Comments
 (0)