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")
|
||||
|
||||
Reference in New Issue
Block a user