From 36da045d719cabd0d7d206b122fd781c25edff74 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 16 Feb 2026 13:45:10 +0000 Subject: [PATCH] Enhance NormalCase functionality: prepopulate age fields on edit, update author handling in create case normal view, and refine template logic for editing permissions --- atlas/forms.py | 18 +++++++++++++- atlas/templates/atlas/normals_list.html | 24 +++++++++---------- .../atlas/partials/_normal_toggle.html | 3 +-- atlas/views.py | 4 +++- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/atlas/forms.py b/atlas/forms.py index 57a453c4..e516468e 100755 --- a/atlas/forms.py +++ b/atlas/forms.py @@ -298,6 +298,22 @@ class NormalCaseForm(ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + # If editing an existing NormalCase, prepopulate age_value/age_unit + try: + instance = kwargs.get('instance') + except Exception: + instance = None + if instance is None: + # also support self.instance when ModelForm sets it + instance = getattr(self, 'instance', None) + if instance is not None and getattr(instance, 'age_days', None) is not None: + try: + val, unit = NormalCase.days_to_value_unit(instance.age_days) + if val is not None and unit is not None: + self.fields['age_value'].initial = val + self.fields['age_unit'].initial = unit + except Exception: + pass self.helper = FormHelper() # Do not render a
tag from crispy here because the template # already provides the surrounding form element (we inject this @@ -315,7 +331,7 @@ class NormalCaseForm(ModelForm): css_class="row", ), Field("notes"), - Submit("submit", "Save", css_class="btn btn-primary"), + # Submit button rendered in modal footer; avoid duplicate button here ) def save(self, commit=True): diff --git a/atlas/templates/atlas/normals_list.html b/atlas/templates/atlas/normals_list.html index ab2b94d2..4a12c9c4 100644 --- a/atlas/templates/atlas/normals_list.html +++ b/atlas/templates/atlas/normals_list.html @@ -32,18 +32,18 @@ {% for normal in page_obj.object_list %}
-
-
{{ normal.case.title }}
- {{ normal.added_date|date:"Y-m-d" }} -
-

- Age: {{ normal.display_age }} - {% if normal.examination %} • Exam: {{ normal.examination }}{% endif %} - {% if normal.modality %} • Modality: {{ normal.modality }}{% endif %} -

- {% if normal.notes %} -

{{ normal.notes }}

- {% endif %} +
+
{{ normal.case.title }}
+ {{ normal.added_date|date:"Y-m-d" }} +
+

+ Age: {{ normal.display_age }} + {% if normal.examination %} • Exam: {{ normal.examination }}{% endif %} + {% if normal.modality %} • Modality: {{ normal.modality }}{% endif %} +

+ {% if normal.notes %} +

{{ normal.notes }}

+ {% endif %}
{% if request.user.is_superuser or request.user in normal.author.all %} diff --git a/atlas/templates/atlas/partials/_normal_toggle.html b/atlas/templates/atlas/partials/_normal_toggle.html index b32679a5..2f1c5f3d 100644 --- a/atlas/templates/atlas/partials/_normal_toggle.html +++ b/atlas/templates/atlas/partials/_normal_toggle.html @@ -15,8 +15,7 @@ {% endif %} - {# Allow NormalCase authors (or atlas editors/superusers) to edit the Normal metadata #} - {% if case.normal_case and (request.user.is_superuser or request.user in case.normal_case.author.all or can_edit) %} + {% if request.user.is_superuser or can_edit or request.user in case.normal_case.author.all %}