From cc7451b1aad2869f7bf598fa89597aecf9a9e72c Mon Sep 17 00:00:00 2001 From: Joshua Laymon Date: Sat, 16 Aug 2025 22:22:09 +0000 Subject: [PATCH] Update web/core/views.py adding endpoint so that illustration 20 words will show in recent --- web/core/views.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/web/core/views.py b/web/core/views.py index 41828f6..e2296e2 100644 --- a/web/core/views.py +++ b/web/core/views.py @@ -15,6 +15,7 @@ from .utils import terms, has_wildcards, wildcard_to_regex, import_csv_bytes from .scripture_normalizer import normalize_scripture_field # <-- NEW from .source_normalizer import normalize_source_field # NEW from .subject_normalizer import normalize_subject_field # NEW +from django.http import JsonResponse # Order + labels used in the Search UI FIELD_ORDER = [ @@ -710,4 +711,33 @@ def normalize_subjects(request): "preview": preview, "limit": limit, }, - ) \ No newline at end of file + ) + from django.http import JsonResponse +# If not already imported above: +# from django.contrib.auth.decorators import login_required +# from django.utils import timezone # only if you need now() +# import re # already in your file + +@login_required +def api_get_recent_views(request): + """ + Return the current user's recently viewed entries (up to 50), + including the illustration text so the UI can show a 20-word snippet. + """ + # Model: RecentView with fields: user (FK), entry (FK Entry), viewed_at (DateTime) + from .models import RecentView # inline to avoid breaking if you split files + + recents = (RecentView.objects + .filter(user=request.user) + .select_related('entry') + .order_by('-viewed_at')[:50]) + + items = [] + for rv in recents: + items.append({ + "entry_id": rv.entry_id, + "viewed_at": rv.viewed_at.isoformat(), + "illustration": rv.entry.illustration or "", + }) + + return JsonResponse({"ok": True, "items": items}) \ No newline at end of file