This commit is contained in:
Joshua Laymon
2025-08-12 22:29:18 -05:00
parent 3458501272
commit 6426211800
7 changed files with 23 additions and 16 deletions
+15 -6
View File
@@ -43,7 +43,6 @@ def search_page(request):
field_options=[{"name":k,"label":label,"checked":bool(selected.get(k))} for k,label in FIELD_ORDER]
q=request.GET.get("q","").strip()
if q:
# AND across terms, OR across selected fields per term
term_list=terms(q)
qs=Entry.objects.all()
fields=[f for f,sel in selected.items() if sel]
@@ -56,7 +55,9 @@ def search_page(request):
request.session["result_ids"]=ids
if ids:
entry=Entry.objects.get(pk=ids[0])
return render(request,"entry_view.html",{"entry":entry,"locked":True,"position":1,"count":len(ids),"from_search":True})
subject_list=[t.strip() for t in (entry.subject or "").split(",") if t.strip()]
scripture_list=[t.strip() for t in (entry.scripture_raw or "").split(";") if t.strip()]
return render(request,"entry_view.html",{"entry":entry,"subject_list":subject_list,"scripture_list":scripture_list,"locked":True,"position":1,"count":len(ids),"from_search":True})
total=Entry.objects.count()
return render(request,"search.html",{"q":q,"selected":selected,"field_options":field_options,"total":total})
return render(request,"search.html",{"selected":default_fields,"field_options":[{"name":k,"label":lbl,"checked":default_fields.get(k,False)} for k,lbl in FIELD_ORDER]})
@@ -67,7 +68,9 @@ def nav_next(request):
if not ids: return redirect("search")
idx=int(request.GET.get("i","0")); idx=min(idx+1, len(ids)-1)
entry=get_object_or_404(Entry, pk=ids[idx])
return render(request,"entry_view.html",{"entry":entry,"locked":True,"position":idx+1,"count":len(ids)})
subject_list=[t.strip() for t in (entry.subject or "").split(",") if t.strip()]
scripture_list=[t.strip() for t in (entry.scripture_raw or "").split(";") if t.strip()]
return render(request,"entry_view.html",{"entry":entry,"subject_list":subject_list,"scripture_list":scripture_list,"locked":True,"position":idx+1,"count":len(ids)})
@login_required
def nav_prev(request):
@@ -75,14 +78,18 @@ def nav_prev(request):
if not ids: return redirect("search")
idx=int(request.GET.get("i","0")); idx=max(idx-1, 0)
entry=get_object_or_404(Entry, pk=ids[idx])
return render(request,"entry_view.html",{"entry":entry,"locked":True,"position":idx+1,"count":len(ids)})
subject_list=[t.strip() for t in (entry.subject or "").split(",") if t.strip()]
scripture_list=[t.strip() for t in (entry.scripture_raw or "").split(";") if t.strip()]
return render(request,"entry_view.html",{"entry":entry,"subject_list":subject_list,"scripture_list":scripture_list,"locked":True,"position":idx+1,"count":len(ids)})
@login_required
def entry_view(request, entry_id):
entry=get_object_or_404(Entry, pk=entry_id)
ids=request.session.get("result_ids",[]); count=len(ids)
position=ids.index(entry.id)+1 if entry.id in ids else 1
return render(request,"entry_view.html",{"entry":entry,"locked":True,"position":position,"count":count})
subject_list=[t.strip() for t in (entry.subject or "").split(",") if t.strip()]
scripture_list=[t.strip() for t in (entry.scripture_raw or "").split(";") if t.strip()]
return render(request,"entry_view.html",{"entry":entry,"subject_list":subject_list,"scripture_list":scripture_list,"locked":True,"position":position,"count":count})
@login_required
def entry_edit(request, entry_id):
@@ -141,10 +148,12 @@ def stats_page(request):
last365=Entry.objects.filter(date_added__gte=today - timedelta(days=365)).count()
buckets=month_buckets_last_12(today)
series=[(label, Entry.objects.filter(date_added__gte=start, date_added__lt=end).count()) for label,start,end in buckets]
peak=max((v for _,v in series), default=1)
heights=[(label, value, 8 + int((value/peak)*100) if peak else 8) for label,value in series]
from collections import Counter
counts=Counter()
for subj in Entry.objects.exclude(subject="").values_list("subject", flat=True):
for tag in [t.strip() for t in subj.split(",") if t.strip()]:
counts[tag.lower()]+=1
top_subjects=[{"name":n.title(),"count":c} for n,c in counts.most_common(10)]
return render(request,"stats.html",{"total":total,"last30":last30,"last365":last365,"series":series,"top_subjects":top_subjects})
return render(request,"stats.html",{"total":total,"last30":last30,"last365":last365,"series":series,"heights":heights,"top_subjects":top_subjects})