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 3 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
11 changes: 9 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 All @@ -933,6 +935,7 @@ def parse_xml(cls, node, runtime, keys):
block.allow_latex = config['allow_latex']
block.allow_learner_resubmissions = config['allow_learner_resubmissions']
block.allow_multiple_files = config['allow_multiple_files']
block.display_name = config['title']
block.file_upload_response = config['file_upload_response']
block.file_upload_type = config['file_upload_type']
block.group_access = config['group_access']
Expand Down Expand Up @@ -1245,6 +1248,10 @@ def is_released(self, step=None):
Returns:
bool
"""
# we only want to check the release status of the block if it is a course block
if self.context_key and not self.context_key.is_course:
return False

# By default, assume that we're published, in case the runtime doesn't support publish date.
if hasattr(self.runtime, 'modulestore'):
is_published = self.runtime.modulestore.has_published_version(self)
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
35 changes: 26 additions & 9 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 @@ -761,7 +767,8 @@ def serialize_content_to_xml(oa_block, root):

# Open assessment displayed title
title = etree.SubElement(root, 'title')
title.text = str(oa_block.title)
title.text = str(oa_block.display_name)
root.set('display_name', str(oa_block.display_name))

# Assessment list
assessments_root = etree.SubElement(root, 'assessments')
Expand Down Expand Up @@ -859,7 +866,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 +949,23 @@ def parse_from_xml(root):

# Retrieve the title
title_el = root.find('title')
if title_el is None:
title = block and block.display_name
if title_el is None and not title:
raise UpdateFromXmlError('Every assessment must contain a "title" element.')
title = _safe_get_text(title_el)
elif title_el is not None:
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 +992,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