improve json editing

This commit is contained in:
Ross
2024-06-10 09:59:43 +01:00
parent bdde50effc
commit 9026ee5390
10 changed files with 155 additions and 9 deletions
+23 -1
View File
@@ -17,6 +17,7 @@ from django.forms import (
from django.forms import inlineformset_factory
from django.shortcuts import get_object_or_404
from django_jsonforms.forms import JSONSchemaField
from django_svelte_jsoneditor.widgets import SvelteJSONEditorWidget
from atlas.models import (
@@ -517,6 +518,21 @@ SeriesImageFormSet = inlineformset_factory(
max_num=2000,
)
class JsonAnswerForm(Form):
json_answer = JSONSchemaField(
schema = "schema/report.json",
#options = 'schema/options.json'
options = {}
)
class Meta:
fields = ["json_answer"]
def __init__(self, *args, case_detail, **kwargs):
super(JsonAnswerForm, self).__init__(*args, **kwargs)
if case_detail.question_schema is not None:
self.fields["json_answer"] = JSONSchemaField(schema=case_detail.question_schema, options={})
class BaseReportAnswerForm(ModelForm):
json_answer = JSONSchemaField(
schema = "schema/report.json",
@@ -721,6 +737,12 @@ class AnswerJSONForm(Form):
)
class CaseDetailForm(ModelForm):
class Meta:
model = CaseDetail
fields = ["sort_order", "question_schema"]#, "user"]
fields = ["sort_order", "question_schema", "question_answers"]#, "user"]
widgets = {
"question_schema": SvelteJSONEditorWidget(),
"question_answers": SvelteJSONEditorWidget(),
}