Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 6 additions & 0 deletions bases/rsptx/assignment_server_api/routers/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,11 @@ async def doAssignment(
del course_attrs["ptx_js_version"]
else:
ptx_js_version = "0.2"
# A book built without WeBWorK does not load pretext-webwork.js in its
# generated _base.html, but an assignment may include WeBWorK questions
# borrowed from another book. Let the template know it must load the
# WeBWorK support itself in that case.
needs_webwork = any(q["question_type"] == "webwork" for q in questionslist)
context = dict( # This is all the variables that will be used in the doAssignment.html document
course=course,
request=request,
Expand Down Expand Up @@ -1036,6 +1041,7 @@ async def doAssignment(
enforce_pastdue=enforce_pastdue,
ptx_js_version=ptx_js_version,
webwork_js_version=webwork_js_version,
needs_webwork=needs_webwork,
latex_preamble_dict=preambles,
wp_imports=get_webpack_static_imports(course),
settings=settings,
Expand Down
25 changes: 25 additions & 0 deletions components/rsptx/templates/assignment/student/doAssignment.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@
{% if origin == "PreTeXt" and using_ptx_base != "true" %}
<link href="/ns/books/published/{{ course.base_course }}/_static/pretext/css/theme.css" rel="stylesheet" />
{% endif %}

{# A book built without WeBWorK does not load pretext-webwork.js in its
generated _base.html, so an assignment that borrows WeBWorK questions
from another book has no handleWW() to activate them. Load the support
here when the assignment needs it and nothing upstream supplied it.
handleWW() is only reached from the Activate button's onclick, so the
injected scripts have until the first click to arrive. #}
{% if needs_webwork %}
<script>
(function () {
var load = function (src) {
var s = document.createElement("script");
s.src = src;
document.head.appendChild(s);
};
if (typeof handleWW === "undefined") {
load("/ns/books/published/{{ course.course_name }}/_static/pretext/js/dist/pretext-webwork.js");
}
// handleWW() calls iFrameResize() on the problem iframe.
if (typeof iFrameResize === "undefined") {
load("https://webwork.runestone.academy/webwork2_files/node_modules/iframe-resizer/js/iframeResizer.min.js");
}
})();
Comment thread
Copilot marked this conversation as resolved.
</script>
Comment on lines +25 to +46

@oscarlevin oscarlevin Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I do not think we need to be as careful as copilot suggests here. If the user clicks activate and handleWW hasn't finished loading, they can just click it again.

{% endif %}
{% endblock %}


Expand Down
Loading