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: Adaptation for the Course Authoring problems structure #33693

Open
wants to merge 1 commit into
base: open-release/quince.master
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions xmodule/capa/capa_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,14 @@ def find_correct_answer_text(self, answer_id):
return answer_id[0]
if xml_element.tag == 'optioninput':
return xml_element.xpath('@correct')[0]
return ', '.join(xml_element.xpath('*[@correct="true"]/text()'))

answers_list = xml_element.xpath('*[@correct="true"]//text()')
cleaned_answers = [answer for answer in answers_list if re.sub(r'[^a-zA-Z0-9\s]', '', answer).strip()]

if not cleaned_answers:
cleaned_answers = xml_element.getparent().xpath('@answer')

return ', '.join(cleaned_answers)

def find_question_label(self, answer_id):
"""
Expand Down Expand Up @@ -625,7 +632,9 @@ def generate_default_question_label():
if questiontext_elem is not None and questiontext_elem.tag in LABEL_ELEMS:
question_text = questiontext_elem.text
else:
question_text = generate_default_question_label()
# Course authoring store a question inside <p> tag within the problem
problem_title = xml_elem.xpath('p') or xml_elem.getparent().xpath('p')
question_text = problem_title[0].text if len(problem_title) == 1 else generate_default_question_label()

return question_text

Expand Down
4 changes: 3 additions & 1 deletion xmodule/capa/inputtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,9 @@ def extract_choices(element, i18n, text_only=False):
if not text_only:
text = stringify_children(choice)
else:
text = choice.text
text_string = choice.xpath('string()')
cleaned_text = re.sub(r'[^a-zA-Z0-9\s]', '', text_string).strip()
text = cleaned_text or text_string
choices.append((choice.get("name"), text))
else:
if choice.tag != 'compoundhint':
Expand Down
Loading