diff --git a/web/core/views.py b/web/core/views.py index fd2fe06..6bde8f2 100644 --- a/web/core/views.py +++ b/web/core/views.py @@ -1021,25 +1021,22 @@ def login_attempts(request): attempts = LoginAttempt.objects.filter(timestamp__gte=cutoff).order_by("-timestamp") return render(request, "tools/login_attempts.html", {"attempts": attempts}) -@login_required -@require_POST -def clear_history(request): + @login_required + @require_POST + def clear_history(request): """ - Clear all 'recents' for the CURRENT user. - We clear the two app-specific keys AND a few common variants in case - your templates or JS ever used alternates. + Clear the current user's history shown on the Search page: + - SearchHistory (last 10 searches) + - ViewedIllustration (recently viewed entries) + Also clears any session keys that might be used as UI caches. """ - KEYS = [ - "recent_searches", # your app’s key for searches - "recent_entries", # your app’s key for viewed entries - # Defensive extras (ignored if unused): - "recent_viewed", "recently_viewed", "recent_results", - "recentSearches", "recentEntries", - ] - cleared = {} - for k in KEYS: - existed = k in request.session + # Delete DB-backed recents for this user + SearchHistory.objects.filter(user=request.user).delete() + ViewedIllustration.objects.filter(user=request.user).delete() + + # (Harmless) clear possible session caches if present + for k in ["recent_searches", "recent_entries", "recent_viewed", "recently_viewed"]: request.session.pop(k, None) - cleared[k] = bool(existed) request.session.modified = True - return JsonResponse({"ok": True, "cleared": cleared}) \ No newline at end of file + + return JsonResponse({"ok": True}) \ No newline at end of file