Update web/core/views.py
adding endpoint so that illustration 20 words will show in recent
This commit is contained in:
parent
04e4bde118
commit
cc7451b1aa
@ -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,
|
||||
},
|
||||
)
|
||||
)
|
||||
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})
|
||||
Loading…
Reference in New Issue
Block a user