Enhance bulk delete functionality by adding user confirmation before submission and removing debug information from the response when no items are deleted.
This commit is contained in:
@@ -2,12 +2,3 @@
|
||||
{% if errors %}
|
||||
<div class="alert alert-warning">Errors: {{ errors }}</div>
|
||||
{% endif %}
|
||||
|
||||
{% if deleted == 0 and debug_post %}
|
||||
<details>
|
||||
<summary>Debug: POST data received</summary>
|
||||
<pre>{{ debug_post|pprint }}</pre>
|
||||
<p>Computed ids: {{ debug_ids }}</p>
|
||||
<p>App: {{ debug_app }}</p>
|
||||
</details>
|
||||
{% endif %}
|
||||
|
||||
+1
-7
@@ -211,8 +211,6 @@ def bulk_delete_questions(request):
|
||||
|
||||
deleted = 0
|
||||
errors = []
|
||||
# For debugging: capture what was received
|
||||
received_post = {k: request.POST.getlist(k) for k in request.POST.keys()}
|
||||
try:
|
||||
qs = Model.objects.filter(pk__in=list(ids))
|
||||
deleted = qs.count()
|
||||
@@ -221,12 +219,8 @@ def bulk_delete_questions(request):
|
||||
logger.exception("bulk_delete failed for app=%s ids=%s", app, ids)
|
||||
return JsonResponse({"ok": False, "error": str(e)}, status=500)
|
||||
|
||||
# Render a small fragment. Include debug info when nothing was deleted to aid diagnosis.
|
||||
# Render a small fragment summarising deletions
|
||||
context = {"deleted": deleted, "errors": errors}
|
||||
if deleted == 0:
|
||||
context["debug_post"] = received_post
|
||||
context["debug_ids"] = sorted(list(ids))
|
||||
context["debug_app"] = app
|
||||
return render(request, "generic/partials/bulk_delete_result.html", context)
|
||||
|
||||
|
||||
|
||||
@@ -81,6 +81,19 @@
|
||||
const uniq = Array.from(new Set(selected.map(String)));
|
||||
console.log('Bulk delete selected ids:', uniq);
|
||||
document.getElementById('bulk-selected-input').value = uniq.join(',');
|
||||
// Confirm with the user before submitting
|
||||
const count = uniq.length;
|
||||
if(count === 0){
|
||||
// nothing selected: prevent submit and show alert
|
||||
e.preventDefault();
|
||||
alert('No items selected for deletion.');
|
||||
return;
|
||||
}
|
||||
const ok = confirm(`Delete ${count} selected question${count === 1 ? '' : 's'}? This cannot be undone.`);
|
||||
if(!ok){
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
// allow HTMX to submit
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user