From e541f83886bd637ceff88c434b2377933624c3a5 Mon Sep 17 00:00:00 2001 From: Joshua Laymon Date: Fri, 22 Aug 2025 00:07:06 +0000 Subject: [PATCH] Update web/core/views.py --- web/core/views.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/web/core/views.py b/web/core/views.py index dc0dc72..38a94a2 100644 --- a/web/core/views.py +++ b/web/core/views.py @@ -19,6 +19,7 @@ from .source_normalizer import normalize_source_field # NEW from .subject_normalizer import normalize_subject_field # NEW from .utils import terms, has_wildcards, wildcard_to_regex, import_csv_bytes from django.contrib.staticfiles.storage import staticfiles_storage +from django.db import transaction # Order + labels used in the Search UI @@ -832,4 +833,27 @@ def stats_page(request): "top_books": top_books, # iterable of (book, count) "top_refs": top_refs, # iterable of (ref, count) }, + +def is_superuser(user): + return user.is_superuser + +@login_required +@user_passes_test(is_superuser) +def delete_all_entries(request): + """ + Confirmation screen + POST to delete ALL Entry records. + Mirrors the style of the single-entry delete page. + """ + if request.method == "POST": + # extra safeguard: only delete if the form had the confirm field + if request.POST.get("confirm") == "yes": + with transaction.atomic(): + from .models import Entry + deleted, _ = Entry.objects.all().delete() + messages.success(request, f"Deleted all illustrations ({deleted} rows).") + return redirect("settings_home") + messages.info(request, "Deletion cancelled.") + return redirect("settings_home") + + return render(request, "settings/delete_all_confirm.html", {}) ) \ No newline at end of file