From 2ac8344b134de0d23d34b02644eba90ab2e2f445 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 30 Jun 2025 13:33:35 +0100 Subject: [PATCH] improve case form --- atlas/forms.py | 8 +- atlas/templates/atlas/case_form.html | 120 +++++++++++++++++---------- atlas/views.py | 19 +++++ 3 files changed, 104 insertions(+), 43 deletions(-) diff --git a/atlas/forms.py b/atlas/forms.py index c97b5130..3aac298d 100755 --- a/atlas/forms.py +++ b/atlas/forms.py @@ -533,6 +533,13 @@ class CaseSeriesForm(ModelForm): else: queryset = Series.objects.all() + # Optimize the queryset for the ModelChoiceField + queryset = queryset.select_related( + "modality" + ).prefetch_related( + "examination", "plane", "contrast", "images" + ) + self.fields["series"] = ModelChoiceField( required=False, queryset=queryset, @@ -541,7 +548,6 @@ class CaseSeriesForm(ModelForm): - class CaseCollectionCaseForm(ModelForm): def __init__(self, *args, user, collection=None, **kwargs): super(CaseCollectionCaseForm, self).__init__(*args, **kwargs) diff --git a/atlas/templates/atlas/case_form.html b/atlas/templates/atlas/case_form.html index 0207334d..b302095a 100755 --- a/atlas/templates/atlas/case_form.html +++ b/atlas/templates/atlas/case_form.html @@ -143,51 +143,87 @@ {% comment %} {{ form }} {% endcomment %} -

Series:

- Add image sets here. These can only be added once created (they can also be added to cases on creation). - -
-
    - {% for form in series_formset %} -
  1. - {{form.non_field_errors}} - {{form.errors}} - {{ form | crispy}} -
  2. - {% endfor %} -
+ +
+ +
+ +
+

Add image sets here. These can only be added once created (they can also be added to cases on creation).

+
+
    + {% for form in series_formset %} +
  1. + {{form.non_field_errors}} + {{form.errors}} + {{ form | crispy}} +
  2. + {% endfor %} +
+
+ {{ series_formset.management_form | crispy }}
- {{ series_formset.management_form | crispy }} -

Differential:

- Add differential here. - -
-
    - {% for form in casedifferential_formset %} -
  1. - {{form.non_field_errors}} - {{form.errors}} - {{ form | crispy}} -
  2. - {% endfor %} -
+
+
+ + +
+ +
+ +
+
+
    + {% for form in casedifferential_formset %} +
  1. + {{form.non_field_errors}} + {{form.errors}} + {{ form | crispy}} +
  2. + {% endfor %} +
+
+ {{ casedifferential_formset.management_form | crispy }}
- {{ casedifferential_formset.management_form | crispy }} -

Resource:

- Add resource here. Resource can be anything that is useful for the case (videos, pdf, etc). This can either be avalaible before attempting the case (such a for a pre reading list) or after. - -
-
    - {% for form in caseresource_formset %} -
  1. - {{form.non_field_errors}} - {{form.errors}} - {{ form | crispy}} -
  2. - {% endfor %} -
+
+
+ + +
+ +
+ +
+
+
    + {% for form in caseresource_formset %} +
  1. + {{form.non_field_errors}} + {{form.errors}} + {{ form | crispy}} +
  2. + {% endfor %} +
+
+ {{ caseresource_formset.management_form | crispy}}
- {{ caseresource_formset.management_form | crispy}} +
+

diff --git a/atlas/views.py b/atlas/views.py index 326915c6..786bc2f3 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -1052,6 +1052,25 @@ class AtlasUpdate( # #initial = {'date_of_death': '05/01/2018'} # exclude = [ 'created_date', 'published_date' ] + + #def get_object(self, queryset=None): + # # Prefetch all related objects needed for the form and formsets + # qs = self.model.objects.select_related( + # # Add all FK fields here + # ).prefetch_related( + # "series__examination", + # "series__plane", + # "series__contrast", + # "series__images", + # "subspecialty", + # "condition", + # "presentation", + # "pathological_process", + # "differentialcase", + # "caseresource_set", + # ) + # return qs.get(pk=self.kwargs["pk"]) + def get_form_kwargs(self): kwargs = super(AtlasUpdate, self).get_form_kwargs() kwargs.update({"user": self.request.user})