nbgrader_jupyterquiz.display.dynamic package
Dynamic subpackage — display entry point.
Submodules
nbgrader_jupyterquiz.display.dynamic.display module
Entry point for displaying quizzes in Jupyter environments.
- nbgrader_jupyterquiz.display.dynamic.display.display_quiz(ref, num=1000000, shuffle_questions=False, shuffle_answers=True, preserve_responses=False, border_radius=10, question_alignment='left', max_width=600, colors=None, load_js=True, grade_id=None)[source]
Display an interactive quiz in a Jupyter notebook.
Parameters
- reflist or str
Question list, DOM element id (
#name:tag), URL, or file path.- numint, optional
Maximum number of questions to show.
- shuffle_questionsbool, optional
Randomise question order on each display.
- shuffle_answersbool, optional
Randomise answer order on each display.
- preserve_responsesbool, optional
Keep student responses visible after answering.
- border_radiusint, optional
CSS border-radius in pixels.
- question_alignmentstr, optional
One of
'left','center','right'.- max_widthint, optional
Maximum quiz width in pixels.
- colorsdict or str, optional
CSS variable overrides, or
'fdsp'for the alternate palette.- load_jsbool, optional
Whether to inline the JavaScript source.
- grade_idstr, optional
Nbgrader
grade_idof the host task cell. When set, the JS recorder persists student responses to aresponses.jsonsidecar file so an autograded test cell can read them vianbgrader_jupyterquiz.autograde.grade_quiz(). WhenNone(the default for non-nbgrader callers), the recorder is a no-op.
nbgrader_jupyterquiz.display.dynamic.loader module
Load question data from a list, file, URL, or DOM element reference.
- nbgrader_jupyterquiz.display.dynamic.loader.load_questions_script(ref, div_id)[source]
Build a JavaScript prefix that loads questions into
questions{div_id}.Parameters
- reflist or str
Question list, DOM element id (starting with
#), HTTP URL, or local file path.- div_idstr
Unique identifier for the quiz container div.
Returns
- scriptstr
JavaScript code that defines the
questions{div_id}variable.- staticbool
Truewhen questions are embedded;Falsefor async URL loading.- urlstr
The source URL when
staticisFalse, otherwise empty string.
nbgrader_jupyterquiz.display.dynamic.renderer module
Render HTML, CSS, and JavaScript components of the quiz display.
- nbgrader_jupyterquiz.display.dynamic.renderer.build_script(prefix_script, static, url, div_id, load_js)[source]
Combine the loading prefix, static JS files, and suffix template.
Parameters
- prefix_scriptstr
JavaScript that defines the questions variable.
- staticbool
Truewhen questions are embedded (use static suffix template).- urlstr
Source URL for async loading when
staticisFalse.- div_idstr
Unique identifier for the container div.
- load_jsbool
Whether to inline the quiz JavaScript source.
Returns
- str
Complete JavaScript block (without surrounding
<script>tags).
- nbgrader_jupyterquiz.display.dynamic.renderer.build_styles(div_id, color_dict)[source]
Build the
<style>block with CSS variables and shared styles.Parameters
- div_idstr
Unique identifier for the container (used for CSS scoping).
- color_dictdict
Mapping of CSS variable names to colour values.
Returns
- str
Complete
<style>tag.
- nbgrader_jupyterquiz.display.dynamic.renderer.render_div(div_id, shuffle_questions, shuffle_answers, preserve_responses, num, max_width, border_radius, question_alignment, grade_id=None)[source]
Build the HTML container div with data attributes and inline style.
Parameters
- div_idstr
Unique identifier for the container.
- shuffle_questionsbool
Whether to shuffle question order.
- shuffle_answersbool
Whether to shuffle answer order.
- preserve_responsesbool
Whether to keep responses visible after answering.
- numint
Maximum number of questions to display.
- max_widthint
Maximum width in pixels.
- border_radiusint
CSS border-radius in pixels.
- question_alignmentstr
CSS text-align value.
- grade_idstr, optional
Nbgrader
grade_idof the host task cell. When provided, emitted asdata-grade-idso the JS recorder persists responses to the sidecar file; omitted whenNone.
Returns
- str
Opening
<div>tag with all required data attributes.