Add example answers form rendering and update viewer iframe
This commit is contained in:
@@ -1307,6 +1307,27 @@ class CaseDetail(models.Model):
|
||||
|
||||
return json.dumps(results)
|
||||
|
||||
def render_example_form(self, request=None):
|
||||
"""Build and return a rendered HTML snippet for the example answers form.
|
||||
|
||||
If `request` is provided it will be passed to the template renderer so
|
||||
csrf tokens and other context processors work correctly. The returned
|
||||
HTML contains the json-editor widget (the `json_answer` field) and a
|
||||
submit button for saving example answers.
|
||||
"""
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.safestring import mark_safe
|
||||
from .forms import JsonAnswerForm
|
||||
|
||||
post_data = {}
|
||||
# Ensure we pass the stored answers into the form so the widget is populated
|
||||
post_data["json_answer"] = json.dumps(self.question_answers) if self.question_answers is not None else json.dumps({})
|
||||
|
||||
form = JsonAnswerForm(post_data, question_schema=self.question_schema)
|
||||
|
||||
html = render_to_string("atlas/_rendered_example_form.html", {"form": form}, request=request)
|
||||
return mark_safe(html)
|
||||
|
||||
class CasePrior(models.Model):
|
||||
case_detail = models.ForeignKey(CaseDetail, on_delete=models.CASCADE)
|
||||
prior_case = models.ForeignKey(Case, on_delete=models.CASCADE, related_name="prior_case")
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
{% load static %}
|
||||
{# Render a small example answers form for a given CaseDetail - expects a context variable `form` (JsonAnswerForm) #}
|
||||
<form method="POST" class="post-form">
|
||||
{% csrf_token %}
|
||||
{# Include any media the field needs (json-editor) #}
|
||||
{% if form.media %}
|
||||
{{ form.media }}
|
||||
{% endif %}
|
||||
|
||||
<div class="json-editor-wrapper">
|
||||
{{ form.json_answer }}
|
||||
</div>
|
||||
|
||||
<div class="mt-2">
|
||||
<button type="submit" name="submit" value="answer" class="btn btn-primary">Save Correct Answers</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -119,7 +119,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% comment %} <iframe id="viewer" style="width: 100%; height: 500px; border: none"></iframe> {% endcomment %}
|
||||
<iframe id="viewer" style="width: 100%; height: 500px; border: none"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user