Skip to content

Conversation

@irtazaakram
Copy link
Member

@irtazaakram irtazaakram commented Oct 15, 2025

This PR applies consistent formatting across all Problem XBlock–related files to align with the formatting conventions used in the xblocks-contrib extraction. The goal is to minimize noise during the extraction review and ensure that only functional differences remain when moving the Problem XBlock out of edx-platform.

We are in the process of extracting the Problem XBlock into xblocks-contrib/problem, where all code and templates are already formatted consistently. To make the migration diff easier for reviewers—and to avoid unnecessary churn caused by formatting—we are pre-formatting the corresponding files inside edx-platform using the same tools and configuration.

Related PR: openedx/xblocks-contrib#63
#37476

HTML / Template Files

There's no known mako template formatter. so we will format html files after converting them to django templates.

JavaScript / CSS Files

prettier --write \
xmodule/capa/tests/test_files/js/mersenne-twister-min.js \
xmodule/capa/tests/test_files/js/test_problem_display.js \
xmodule/capa/tests/test_files/js/test_problem_generator.js \
xmodule/capa/tests/test_files/js/test_problem_grader.js \
xmodule/capa/tests/test_files/js/xproblem.js \
xmodule/js/spec/capa/display_spec.js \
xmodule/js/spec/capa/imageinput_spec.js \
xmodule/js/spec/collapsible_spec.js \
xmodule/js/spec/helper.js \
xmodule/js/src/capa/display.js \
xmodule/js/src/capa/imageinput.js \
xmodule/js/src/capa/schematic.js \
xmodule/js/src/collapsible.js \
xmodule/js/src/javascript_loader.js \
xmodule/js/src/problem/edit.js \
xmodule/static/css-builtin-blocks/ProblemBlockDisplay.css \
xmodule/static/css-builtin-blocks/ProblemBlockEditor.css

YAML Files

prettier --write "xmodule/templates/problem/**/*.y?(a)ml"
  • No logic changes — formatting only
  • Consistent style across Problem XBlock files

Testing:

  • Created a Multiple Choice problem in the Visual Editor, submitted the correct option, and confirmed the Green Check appeared.
  • Submitted an incorrect option in the same Multiple Choice problem and confirmed the Red X appeared.
  • Configured a Checkbox problem with partial_credit="EDC", selected a mix of right/wrong answers, and confirmed a partial score (e.g., 50%) was awarded.
  • Configured a Checkbox problem with partial_credit="halves", selected one wrong option, and confirmed the score was cut exactly in half.
  • Configured a Dropdown problem with inline="1" and confirmed the dropdown rendered inside the text flow, not on a new line.
  • Configured a Text Input with type="ci" (Case Insensitive), submitted "paris" for answer "Paris", and verified it was accepted.
  • Configured a Text Input with type="cs" (Case Sensitive), submitted "paris" for answer "Paris", and verified it was rejected.
  • Configured a Numerical Input with a tolerance of 0.5, submitted a value on the boundary (e.g., 10.5 for 10), and confirmed it was marked Correct.
  • Configured a Numerical Input with an answer range (e.g., [1, 2]), submitted a value inside the range, and confirmed it was marked Correct.
  • Entered text into a problem, clicked Save, performed a hard refresh, and confirmed the text remained saved.
  • Modified max_attempts to 1, submitted an answer, and confirmed the Submit button disabled immediately.
  • Modified max_attempts to 3, submitted incorrect answers, and confirmed the button remained enabled until the 3rd submission.
  • Modified max_attempts to 0 (unlimited) and confirmed the problem never locks regardless of submissions.
  • Enabled show_reset_button="true", clicked Reset on an un-submitted input, and confirmed the field cleared.
  • Enabled show_reset_button="false" and confirmed the Reset button was hidden in the LMS.
  • Set showanswer="always" and confirmed the Show Answer button was visible immediately upon page load.
  • Set showanswer="answered" and confirmed the button appeared only after a correct submission.
  • Set showanswer="attempted" and confirmed the button appeared after the first incorrect submission.
  • Set showanswer="past_due", manipulated the due date to the past, and confirmed the button appeared immediately.
  • Enabled rerandomize="on_reset" (on a problem with a Python script), clicked Reset, and confirmed the random values changed.
  • Enabled rerandomize="never", clicked Reset, and confirmed that only inputs cleared while the random values remained static.
  • Enabled shuffle="true" on a Multiple Choice problem, reloaded the page 3 times, and confirmed the order of answers changed.
  • Switched a problem to the Advanced Editor to add custom XML (e.g., <choicehint>), then attempted to switch back to the Visual Editor to confirm the system prevented the action.
  • Configured a Math Expression problem, submitted a symbolically equivalent answer (e.g., 1 + x^2 for x^2 + 1), and confirmed the parser accepted it.
  • Configured a Drag and Drop problem in Standard Mode, dragged an incorrect item, and confirmed it immediately snapped back with feedback.
  • Configured a Drag and Drop problem in Assessment Mode, dragged items, clicked Submit, and confirmed no feedback occurred until submission.

During testing on the sandbox, the following problems were observed to be non-functional, but this is not caused by the changes in this PR

  • Custom JavaScript Display & Grading
  • Custom Python-evaluated input

Relevant issue: #36538

@irtazaakram irtazaakram marked this pull request as draft October 15, 2025 07:01
@irtazaakram irtazaakram force-pushed the autoformat-problemblock-js-html-css-yaml branch from 424f7c6 to de9e343 Compare October 20, 2025 10:05
@irtazaakram irtazaakram force-pushed the autoformat-problemblock-js-html-css-yaml branch 2 times, most recently from b155f98 to fb2e660 Compare November 11, 2025 11:48
@irtazaakram irtazaakram added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Nov 11, 2025
@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@irtazaakram irtazaakram added create-sandbox open-craft-grove should create a sandbox environment from this PR and removed create-sandbox open-craft-grove should create a sandbox environment from this PR labels Nov 12, 2025
@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@irtazaakram irtazaakram force-pushed the autoformat-problemblock-js-html-css-yaml branch 2 times, most recently from 069382b to ab72bf9 Compare December 1, 2025 15:49
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@irtazaakram irtazaakram force-pushed the autoformat-problemblock-js-html-css-yaml branch from ab72bf9 to 85df359 Compare December 2, 2025 09:11
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@irtazaakram irtazaakram force-pushed the autoformat-problemblock-js-html-css-yaml branch from bda2c75 to b574e9c Compare December 3, 2025 07:06
@irtazaakram irtazaakram force-pushed the autoformat-problemblock-js-html-css-yaml branch 2 times, most recently from ee30435 to 0b84a2c Compare December 3, 2025 07:22
@irtazaakram irtazaakram force-pushed the autoformat-problemblock-js-html-css-yaml branch from 0b84a2c to 9209971 Compare December 3, 2025 07:38
});

// split scripts and preformatted sections, and wrap paragraphs
splits = xml.split(/(<\/?(?:script|pre|label|description)[^>]*>)/gi);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var answers;
answers = response.answers;
$.each(answers, function (key, value) {
var safeKey = key.replace(/\\/g, "\\\\").replace(/:/g, "\\:").replace(/\./g, "\\."); // fix for courses which use url_names with colons & periods, e.g. problem:question1, question1.1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var answer, choice, inputId, i, len, results, $element, $inputLabel, $inputStatus;
$element = $(element);
inputId = $element.attr("id").replace(/inputtype_/, "");
var safeId = inputId.replace(/\\/g, "\\\\").replace(/:/g, "\\:").replace(/\./g, "\\."); // fix for courses which use url_names with colons & periods, e.g. problem:question1, question1.1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!(src_escaped in loaded)) {
loaded[src_escaped] = true;
s = document.createElement("script");
s.setAttribute("src", src_escaped);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@irtazaakram irtazaakram marked this pull request as ready for review December 4, 2025 07:57
@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@salman2013
Copy link
Contributor

salman2013 commented Dec 8, 2025

The PR looks good to me, I believe the fixes as you explained me will improve things. Please keep an eye on the logs after the merge. Few tests are pending once that will pass then you can merge it.

Copy link
Contributor

@salman2013 salman2013 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@irtazaakram irtazaakram merged commit c3e8542 into master Dec 8, 2025
53 checks passed
@irtazaakram irtazaakram deleted the autoformat-problemblock-js-html-css-yaml branch December 8, 2025 15:01
@irtazaakram irtazaakram changed the title Autoformat Problem XBlock Source Files for Consistency (2/2) Autoformat Problem XBlock Source Files for Consistency (2/3) Dec 15, 2025
mraman-2U pushed a commit to mraman-2U/edx-platform that referenced this pull request Dec 24, 2025
…#37487)

* fix: run prettier on problem block code

* fix: codeql issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

create-sandbox open-craft-grove should create a sandbox environment from this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants