From 556936021fcba21ef4846e43f8127ab5553b97ac Mon Sep 17 00:00:00 2001 From: Joshua Laymon Date: Sat, 16 Aug 2025 22:36:53 +0000 Subject: [PATCH] Update web/core/views.py --- web/core/views.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/web/core/views.py b/web/core/views.py index 97bd0c5..67425cf 100644 --- a/web/core/views.py +++ b/web/core/views.py @@ -9,6 +9,7 @@ from django.db.models import Q from django.http import HttpResponse, JsonResponse from django.shortcuts import render, redirect, get_object_or_404 from django.views.decorators.http import require_http_methods +from django.utils.text import Truncator from .forms import ImportForm, EntryForm from .models import Entry @@ -616,10 +617,9 @@ def normalize_subjects(request): 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. + including a precomputed 20-word snippet from illustration (or a sensible fallback). """ - # Model: RecentView with fields: user (FK), entry (FK Entry), viewed_at (DateTime) - from .models import RecentView # local import to avoid issues in old migrations + from .models import RecentView recents = ( RecentView.objects @@ -628,12 +628,20 @@ def api_get_recent_views(request): .order_by("-viewed_at")[:50] ) + def make_snippet(e): + base = (e.illustration or "").strip() or (e.application or "").strip() or (e.subject or "").strip() + if not base: + return "" + return Truncator(" ".join(base.split())).words(20, truncate="…") + items = [] for rv in recents: + e = rv.entry items.append({ "entry_id": rv.entry_id, "viewed_at": rv.viewed_at.isoformat(), - "illustration": rv.entry.illustration or "", + "illustration": e.illustration or "", + "snippet": make_snippet(e), }) return JsonResponse({"ok": True, "items": items}) \ No newline at end of file