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: make it work in library v2 #2272

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions openassessment/xblock/openassessmentblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ def api_data(self):

@property
def course_id(self):
return str(self.xmodule_runtime.course_id) # pylint: disable=no-member
if hasattr(self, "xmodule_runtime"):
return str(self.xmodule_runtime.course_id) # pylint: disable=no-member
return None

@cached_property
def course(self):
Expand Down Expand Up @@ -917,8 +919,8 @@ def parse_xml(cls, node, runtime, keys):
Inherited by XBlock core.

"""
config = parse_from_xml(node)
block = runtime.construct_xblock_from_class(cls, keys)
config = parse_from_xml(node, block)

xblock_validator = validator(block, block._, strict_post_release=False)
xblock_validator(
Expand Down
5 changes: 4 additions & 1 deletion openassessment/xblock/studio_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.fields import List, Scope
from opaque_keys.edx.locator import LibraryLocatorV2

from django.template.loader import get_template
from django.utils.translation import gettext_lazy
Expand Down Expand Up @@ -454,7 +455,7 @@ def get_base_url_path_for_course_assets(self, course_key):
"""
Returns base url path for course assets
"""
if course_key is None:
if (course_key is None) or isinstance(course_key, LibraryLocatorV2):
return None

placeholder_id = uuid4().hex
Expand All @@ -478,6 +479,8 @@ def get_teamsets(self, course_id):
"""
Wrapper around get_team_configuration that returns team names only for display
"""
if isinstance(course_id, LibraryLocatorV2):
return None
team_configuration = self.get_team_configuration(course_id)
if not team_configuration:
return None
Expand Down
32 changes: 24 additions & 8 deletions openassessment/xblock/utils/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def _parse_prompts_xml(root):
raise UpdateFromXmlError('Every "prompt" element must contain a "description" element.')

prompts_list.append(prompt_dict)
else:
elif root.find('rubric'):
# For backwards compatibility. Initially a single prompt element was added in
# the rubric element.
rubric_el = root.find('rubric')
Expand All @@ -290,6 +290,12 @@ def _parse_prompts_xml(root):
'description': prompt_description,
}
)
else:
prompts_list.append(
{
'description': '',
}
)

return prompts_list

Expand Down Expand Up @@ -859,7 +865,7 @@ def serialize_assessments_to_xml_str(oa_block):
return etree.tostring(assessments_root, pretty_print=True, encoding='unicode')


def parse_from_xml(root):
def parse_from_xml(root, block=None):
"""
Update the OpenAssessment XBlock's content from an XML definition.

Expand Down Expand Up @@ -942,15 +948,23 @@ def parse_from_xml(root):

# Retrieve the title
title_el = root.find('title')
if title_el is None:
title = block and block.title
if title_el is None and not title:
raise UpdateFromXmlError('Every assessment must contain a "title" element.')
title = _safe_get_text(title_el)
if title_el:
title = _safe_get_text(title_el)

# Retrieve the rubric
rubric_el = root.find('rubric')
if rubric_el is None:
rubric = block and {
'criteria': block.rubric_criteria,
'feedbackprompt': block.rubric_feedback_prompt,
'feedback_default_text': block.rubric_feedback_default_text,
}
if rubric_el is None and rubric is None:
raise UpdateFromXmlError('Every assessment must contain a "rubric" element.')
rubric = parse_rubric_xml(rubric_el)
if rubric_el:
rubric = parse_rubric_xml(rubric_el)

# Retrieve the prompts
prompts = _parse_prompts_xml(root)
Expand All @@ -977,9 +991,11 @@ def parse_from_xml(root):

# Retrieve the assessments
assessments_el = root.find('assessments')
if assessments_el is None:
assessments = block and block.valid_assessments
if assessments_el is None and block is None:
raise UpdateFromXmlError('Every assessment must contain an "assessments" element.')
assessments = parse_assessments_xml(assessments_el)
if assessments_el:
assessments = parse_assessments_xml(assessments_el)

return {
'title': title,
Expand Down
Loading