Update web/core/views.py

This commit is contained in:
Joshua Laymon 2025-08-22 00:07:06 +00:00
parent a7af243d2d
commit e541f83886

View File

@ -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", {})
)