Refactor NormalCase model: remove 'added_by' field, add 'author' ManyToManyField; update related views and templates for editing functionality

This commit is contained in:
Ross
2026-02-16 13:32:06 +00:00
parent 64103cac1e
commit 0b6661c018
9 changed files with 134 additions and 25 deletions
+14 -2
View File
@@ -30,7 +30,8 @@
{% if page_obj.object_list %}
<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 %}">
<div class="list-group-item d-flex justify-content-between align-items-start">
<a class="flex-grow-1 text-decoration-none text-reset" href="{% url 'atlas:case_detail' normal.case.pk %}">
<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>
@@ -43,7 +44,18 @@
{% if normal.notes %}
<p class="mb-0 text-muted">{{ normal.notes }}</p>
{% endif %}
</a>
</a>
<div class="ms-2">
{% if request.user.is_superuser or request.user in normal.author.all %}
<button class="btn btn-sm btn-outline-secondary"
hx-get="{% url 'atlas:case_normal_edit' normal.pk %}"
hx-target="body"
hx-swap="beforeend">
Edit
</button>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{% else %}
@@ -1,10 +1,10 @@
<div id="normal-modal-{{ case.pk }}" class="modal modal-blur fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered" role="document">
<div class="modal-content">
<form method="post" hx-post="{% url 'atlas:case_create_normal' case.pk %}" hx-target="#normal-toggle-block" hx-swap="outerHTML">
<form method="post" hx-post="{% if normal %}{% url 'atlas:case_normal_edit' normal.pk %}{% else %}{% url 'atlas:case_create_normal' case.pk %}{% endif %}" hx-target="#normal-toggle-block" hx-swap="outerHTML">
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title">Mark case {{ case.pk }} as Normal</h5>
<h5 class="modal-title">{% if normal %}Edit normal for case {{ case.pk }}{% else %}Mark case {{ case.pk }} as Normal{% endif %}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
@@ -4,15 +4,27 @@
{% if case.normal_case %}
<span class="badge bg-success">Normal</span>
<small class="text-muted">{{ case.normal_case.display_age }}</small>
{% if can_edit %}
<button class="btn btn-sm btn-outline-danger ms-2"
hx-post="{% url 'atlas:case_toggle_normal' case.pk %}"
hx-target="#normal-toggle-block"
hx-swap="outerHTML"
hx-confirm="Unmark this case as normal?">
Unmark normal
</button>
{% endif %}
<span>
{% if can_edit %}
<button class="btn btn-sm btn-outline-danger ms-2"
hx-post="{% url 'atlas:case_toggle_normal' case.pk %}"
hx-target="#normal-toggle-block"
hx-swap="outerHTML"
hx-confirm="Unmark this case as normal?">
Unmark normal
</button>
{% 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) %}
<button class="btn btn-sm btn-outline-secondary ms-2"
hx-get="{% url 'atlas:case_normal_edit' case.normal_case.pk %}"
hx-target="body"
hx-swap="beforeend">
Edit Normal
</button>
{% endif %}
</span>
{% else %}
{% if can_edit %}
<button class="btn btn-sm btn-outline-primary"