Enhance normals list display and update case state handling in views

This commit is contained in:
Ross
2025-11-13 22:17:43 +00:00
parent 970242e1fb
commit 8da2dd27da
2 changed files with 28 additions and 2 deletions
+12 -2
View File
@@ -27,8 +27,18 @@
<div class="list-group">
{% for normal in page_obj.object_list %}
<a class="list-group-item list-group-item-action" href="{% url 'atlas:case_detail' normal.case.pk %}">
{{ normal.case.title }}{% if normal.age_years %} — {{ normal.age_years }} yrs{% endif %}
<div class="small text-muted">Added {{ normal.added_date }}</div>
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ normal.case.title }}</h5>
<small class="text-muted">{{ normal.added_date|date:"Y-m-d" }}</small>
</div>
<p class="mb-1">
Age: {{ normal.age_years|default:"unknown" }} yrs
{% if normal.examination %} • Exam: {{ normal.examination }}{% endif %}
{% if normal.modality %} • Modality: {{ normal.modality }}{% endif %}
</p>
{% if normal.notes %}
<p class="mb-0 text-muted">{{ normal.notes }}</p>
{% endif %}
</a>
{% endfor %}
</div>
+16
View File
@@ -500,6 +500,14 @@ def toggle_case_normal(request, pk):
if normal is not None:
normal.delete()
# Remove any cached relation on the case and reload so the template
# sees the updated state (no normal_case).
try:
if hasattr(case, "normal_case"):
delattr(case, "normal_case")
except Exception:
pass
case = get_case_for_case_detail(pk)
else:
# Attempt to auto-extract age from DICOM
age = None
@@ -668,6 +676,14 @@ def create_case_normal(request, pk):
nc.added_by = request.user
nc.save()
# Ensure the case reflects the newly created NormalCase when rendering
try:
if hasattr(case, "normal_case"):
delattr(case, "normal_case")
except Exception:
pass
case = get_case_for_case_detail(pk)
# Return the updated toggle fragment and close modal via inline script
is_atlas_editor = request.user.is_superuser or request.user.groups.filter(name="atlas_editor").exists()
is_case_author = case.author.filter(id=request.user.id).exists()