-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow javascript in attempts and small demo
- Loading branch information
1 parent
340be86
commit 0920cbd
Showing
13 changed files
with
251 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
console.log("Hello world!"); | ||
define(function () { | ||
return { | ||
initButton: function (attempt) { | ||
attempt.getElementById("mybutton").addEventListener("click", function (event) { | ||
event.target.disabled = true; | ||
attempt.getElementById("hiddenInput").value = "secret"; | ||
}) | ||
}, | ||
hello: function (attempt, param) { | ||
console.log("hello " + param); | ||
}, | ||
} | ||
}); |
13 changes: 12 additions & 1 deletion
13
examples/static-files/python/local/static_files_example/question_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
examples/static-files/python/local/static_files_example/templates/formulation.xhtml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<div xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:qpy="http://questionpy.org/ns/question"> | ||
<div class="my-custom-class">I have custom styling!</div> | ||
<input type="hidden" name="hidden_value" id="hiddenInput" /> | ||
<input type="button" id="mybutton" value="click here for a 1.0 score" /> | ||
</div> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,14 @@ | |
# (c) Technische Universität Berlin, innoCampus <[email protected]> | ||
from typing import Literal, TypedDict | ||
|
||
from questionpy_common.api.attempt import AttemptModel, AttemptScoredModel, AttemptStartedModel | ||
from questionpy_common.api.attempt import ( | ||
AttemptModel, | ||
AttemptScoredModel, | ||
AttemptStartedModel, | ||
JsModuleCall, | ||
JsModuleCallRoleFeedback, | ||
) | ||
from questionpy_common.manifest import Manifest | ||
from questionpy_sdk.webserver.question_ui import ( | ||
QuestionDisplayOptions, | ||
QuestionFormulationUIRenderer, | ||
|
@@ -15,6 +22,7 @@ | |
class _AttemptRenderContext(TypedDict): | ||
attempt_status: Literal["Started", "In progress", "Scored"] | ||
|
||
manifest: Manifest | ||
attempt: AttemptModel | ||
attempt_state: str | ||
|
||
|
@@ -26,10 +34,39 @@ class _AttemptRenderContext(TypedDict): | |
specific_feedback: str | None | ||
right_answer: str | None | ||
|
||
javascript_calls: list[JsModuleCall] | ||
|
||
render_errors: RenderErrorCollections | ||
|
||
|
||
def filter_js_calls_by_role_feedback( | ||
calls: list[JsModuleCall], display_options: QuestionDisplayOptions | ||
) -> list[JsModuleCall]: | ||
def role_feedback_allowed(call: JsModuleCall) -> bool: | ||
match call.if_role_feedback: | ||
case None: | ||
return True | ||
case ( | ||
JsModuleCallRoleFeedback.TEACHER | ||
| JsModuleCallRoleFeedback.DEVELOPER | ||
| JsModuleCallRoleFeedback.SCORER | ||
| JsModuleCallRoleFeedback.PROCTOR | ||
): | ||
return call.if_role_feedback in display_options.roles | ||
case JsModuleCallRoleFeedback.GENERAL_FEEDBACK: | ||
return display_options.general_feedback | ||
case JsModuleCallRoleFeedback.SPECIFIC_FEEDBACK: | ||
return display_options.specific_feedback | ||
case JsModuleCallRoleFeedback.RIGHT_ANSWER: | ||
return display_options.right_answer | ||
|
||
return False | ||
|
||
return list(filter(role_feedback_allowed, calls)) | ||
|
||
|
||
def get_attempt_render_context( | ||
manifest: Manifest, | ||
attempt: AttemptModel, | ||
attempt_state: str, | ||
*, | ||
|
@@ -55,6 +92,8 @@ def get_attempt_render_context( | |
"form_disabled": disabled, | ||
"formulation": html, | ||
"attempt": attempt, | ||
"manifest": manifest, | ||
"javascript_calls": filter_js_calls_by_role_feedback(attempt.ui.javascript_calls, display_options), | ||
"general_feedback": None, | ||
"specific_feedback": None, | ||
"right_answer": None, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.