Refactor case management links and add case list item partial for improved organization and rendering in collection detail view
This commit is contained in:
+24
-1
@@ -1151,7 +1151,25 @@ def add_case_to_collection(request, collection_id):
|
||||
|
||||
print(case)
|
||||
collection.add_case(case)
|
||||
return HttpResponse(f"Case added to collection {collection.name} (refresh to see)")
|
||||
# Render the new case list item and return it so HTMX can append it
|
||||
try:
|
||||
casedetail = collection.casedetail_set.get(case=case)
|
||||
except Exception:
|
||||
return HttpResponse("Case added, but could not render item.")
|
||||
|
||||
total = collection.casedetail_set.count()
|
||||
can_edit = request.user.is_superuser or collection.author.filter(pk=request.user.pk).exists()
|
||||
rendered = render_to_string(
|
||||
"atlas/partials/case_list_item.html",
|
||||
{
|
||||
"casedetail": casedetail,
|
||||
"collection": collection,
|
||||
"forloop": {"counter": total, "counter0": max(0, total - 1)},
|
||||
"can_edit": can_edit,
|
||||
},
|
||||
request=request,
|
||||
)
|
||||
return HttpResponse(rendered)
|
||||
|
||||
# if request.method == "POST":
|
||||
|
||||
@@ -4215,6 +4233,11 @@ def remove_case_from_collection(request, case_pk, collection_pk):
|
||||
# Remove the case from the collection
|
||||
collection.cases.remove(case)
|
||||
|
||||
# If this was an HTMX request, return an empty response so the caller
|
||||
# can swap out (remove) the surrounding element (e.g., the <li>).
|
||||
if request.htmx:
|
||||
return HttpResponse("")
|
||||
|
||||
return HttpResponse(f"Case removed from collection: {collection.name}")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user