add question schema model and integrate most urls/views
This commit is contained in:
+77
-11
@@ -49,6 +49,7 @@ from .forms import (
|
||||
ConditionForm,
|
||||
FindingForm,
|
||||
JsonAnswerForm,
|
||||
QuestionSchemaForm,
|
||||
ResourceForm,
|
||||
SelfReviewForm,
|
||||
SeriesAuthorForm,
|
||||
@@ -70,6 +71,7 @@ from .models import (
|
||||
Differential,
|
||||
PathologicalProcess,
|
||||
Presentation,
|
||||
QuestionSchema,
|
||||
Resource,
|
||||
SelfReview,
|
||||
Series,
|
||||
@@ -89,6 +91,7 @@ from .tables import (
|
||||
FindingTable,
|
||||
PathologicalProcessTable,
|
||||
PresentationTable,
|
||||
QuestionSchemaTable,
|
||||
SeriesTable,
|
||||
StructureTable,
|
||||
SubspecialtyTable,
|
||||
@@ -100,6 +103,7 @@ from .filters import (
|
||||
FindingFilter,
|
||||
PathologicalProcessFilter,
|
||||
PresentationFilter,
|
||||
QuestionSchemaFilter,
|
||||
SeriesFilter,
|
||||
StructureFilter,
|
||||
SubspecialtyFilter,
|
||||
@@ -224,6 +228,33 @@ def series_detail(request, pk, finding_pk=None):
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
# @user_is_atlas_editor
|
||||
def question_schema_detail(request, pk: int):
|
||||
question_schema = get_object_or_404(QuestionSchema, pk=pk)
|
||||
|
||||
example_form = question_schema.get_example_form()
|
||||
|
||||
# logging.debug(atlas.subspecialty.first().name.all())
|
||||
return render(
|
||||
request,
|
||||
"atlas/question_schema_detail.html",
|
||||
{"question_schema": question_schema, "example_form": example_form},
|
||||
)
|
||||
|
||||
@login_required
|
||||
# @user_is_atlas_editor
|
||||
def question_schema_schemas(request):
|
||||
question_schemas = QuestionSchema.objects.all()
|
||||
|
||||
return render(
|
||||
request,
|
||||
"atlas/question_schemas_preset.html",
|
||||
{
|
||||
"question_schemas": question_schemas,
|
||||
},
|
||||
)
|
||||
|
||||
@login_required
|
||||
# @user_is_atlas_editor
|
||||
def condition_detail(request, pk):
|
||||
@@ -823,6 +854,18 @@ class ConditionCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
form_class = ConditionForm
|
||||
|
||||
|
||||
class QuestionSchemaCreate(LoginRequiredMixin, CreateView):
|
||||
model = QuestionSchema
|
||||
form_class = QuestionSchemaForm
|
||||
|
||||
class QuestionSchemaUpdate(LoginRequiredMixin, UpdateView):
|
||||
model = QuestionSchema
|
||||
form_class = QuestionSchemaForm
|
||||
|
||||
class QuestionSchemaDelete(AuthorOrCheckerRequiredMixin, DeleteView):
|
||||
model = QuestionSchema
|
||||
template_name = "confirm_delete.html"
|
||||
|
||||
class FindingUpdate(RevisionMixin, LoginRequiredMixin, UpdateView):
|
||||
model = Finding
|
||||
form_class = FindingForm
|
||||
@@ -1141,6 +1184,14 @@ class ConditionView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
filterset_class = ConditionFilter
|
||||
|
||||
|
||||
class QuestionSchemaView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
model = QuestionSchema
|
||||
table_class = QuestionSchemaTable
|
||||
template_name = "atlas/view.html"
|
||||
|
||||
filterset_class = QuestionSchemaFilter
|
||||
|
||||
|
||||
class SubspecialtyView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
model = Subspecialty
|
||||
table_class = SubspecialtyTable
|
||||
@@ -1484,8 +1535,17 @@ class CollectionView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
def collection_viva(request, pk):
|
||||
collection = get_object_or_404(CaseCollection, pk=pk)
|
||||
|
||||
cases = collection.cases.all().order_by("casedetail__sort_order").prefetch_related("series", "series__images", "series__contrast", "series__plane", "series__examination")
|
||||
|
||||
cases = (
|
||||
collection.cases.all()
|
||||
.order_by("casedetail__sort_order")
|
||||
.prefetch_related(
|
||||
"series",
|
||||
"series__images",
|
||||
"series__contrast",
|
||||
"series__plane",
|
||||
"series__examination",
|
||||
)
|
||||
)
|
||||
|
||||
return render(
|
||||
request,
|
||||
@@ -1588,7 +1648,9 @@ def collection_case_details(request, exam_id, case_id):
|
||||
# answers = request.POST
|
||||
case_detail.question_answers = json.loads(request.POST.get("json_answer"))
|
||||
case_detail.save()
|
||||
example_form = JsonAnswerForm(request.POST, case_detail=case_detail)
|
||||
example_form = JsonAnswerForm(
|
||||
request.POST, question_schema=case_detail.question_schema
|
||||
)
|
||||
form = CaseDetailForm(instance=case_detail)
|
||||
# Called if the user saves the main form
|
||||
elif request.POST.get("submit") == "save":
|
||||
@@ -1596,7 +1658,7 @@ def collection_case_details(request, exam_id, case_id):
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
# Add any additional logic or redirection here
|
||||
# example_form = JsonAnswerForm(request.POST, case_detail=case_detail)
|
||||
# example_form = JsonAnswerForm(request.POST, question_schema=case_detail.question_schema)
|
||||
post_data = request.POST.copy()
|
||||
if (
|
||||
case_detail.question_schema is not None
|
||||
@@ -1618,7 +1680,9 @@ def collection_case_details(request, exam_id, case_id):
|
||||
post_data["json_answer"] = json.dumps(answers)
|
||||
case_detail.question_answers = answers
|
||||
case_detail.save()
|
||||
example_form = JsonAnswerForm(post_data, case_detail=case_detail)
|
||||
example_form = JsonAnswerForm(
|
||||
post_data, question_schema=case_detail.question_schema
|
||||
)
|
||||
|
||||
form = CaseDetailForm(instance=case_detail)
|
||||
# This shouldn't happen
|
||||
@@ -1629,7 +1693,9 @@ def collection_case_details(request, exam_id, case_id):
|
||||
else:
|
||||
post_data = request.POST.copy()
|
||||
post_data["json_answer"] = json.dumps(case_detail.question_answers)
|
||||
example_form = JsonAnswerForm(post_data, case_detail=case_detail)
|
||||
example_form = JsonAnswerForm(
|
||||
post_data, question_schema=case_detail.question_schema
|
||||
)
|
||||
|
||||
form = CaseDetailForm(instance=case_detail)
|
||||
pass
|
||||
@@ -1652,17 +1718,18 @@ def collection_case_details(request, exam_id, case_id):
|
||||
# post_data = request.POST.copy()
|
||||
# post_data["json_answer"]= json.dumps(answers)
|
||||
# case_detail.question_answers = answers
|
||||
# example_form = JsonAnswerForm(post_data, case_detail=case_detail)
|
||||
# example_form = JsonAnswerForm(post_data, question_schema=case_detail.question_schema)
|
||||
|
||||
# form = CaseDetailForm(instance=case_detail)
|
||||
|
||||
# blank_form = JsonAnswerForm(case_detail=case_detail)
|
||||
case_number, case_count = collection.get_index_of_case(case_detail.case, case_count=True)
|
||||
# blank_form = JsonAnswerForm(question_schema=case_detail.question_schema)
|
||||
case_number, case_count = collection.get_index_of_case(
|
||||
case_detail.case, case_count=True
|
||||
)
|
||||
|
||||
previous = collection.get_previous_case(case_detail.case)
|
||||
next = collection.get_next_case(case_detail.case)
|
||||
|
||||
|
||||
return render(
|
||||
request,
|
||||
"atlas/collection_case_detail.html",
|
||||
@@ -1983,7 +2050,6 @@ def collection_case_view_take(
|
||||
).first()
|
||||
ReportAnswerForm = UserQuestionAnswerForm
|
||||
|
||||
|
||||
if request.method == "POST":
|
||||
if collection.collection_type in ("REP", "QUE"):
|
||||
if not collection.publish_results:
|
||||
|
||||
Reference in New Issue
Block a user