Update web/core/views.py
This commit is contained in:
parent
574dd3bf3c
commit
151fd807d8
@ -188,7 +188,7 @@ def search_page(request):
|
||||
ctx = entry_context(entry, ids)
|
||||
ctx.update({"from_search": True})
|
||||
|
||||
# 🔽 ADD THIS
|
||||
# 🔽 ADD THIS
|
||||
if request.user.is_staff:
|
||||
ctx["tts_url"] = reverse("api_tts_for_entry", args=[entry.id])
|
||||
|
||||
@ -511,7 +511,7 @@ def export_csv(request):
|
||||
# series = [
|
||||
# (label, Entry.objects.filter(date_added__gte=start, date_added__lt=end).count())
|
||||
# for label, start, end in months
|
||||
# ]
|
||||
# ]
|
||||
# peak = max((v for _, v in series), default=1)
|
||||
# heights = [
|
||||
# (label, value, 8 + int((value / peak) * 100) if peak else 8)
|
||||
@ -1052,26 +1052,29 @@ def audit_log(request):
|
||||
return render(request, "tools/audit_log.html", {"rows": rows})
|
||||
|
||||
|
||||
from django.contrib.staticfiles import finders
|
||||
from django.http import HttpResponseBadRequest, HttpResponseRedirect
|
||||
from django.urls import reverse
|
||||
import os
|
||||
|
||||
# === Theme selection (robust) ================================================
|
||||
def _is_valid_theme(name: str) -> bool:
|
||||
# Validate against files present in /static/themes
|
||||
for finder in finders.get_finders():
|
||||
for path, storage in finder.list(['themes']):
|
||||
if path == f'themes/{name}.css':
|
||||
return True
|
||||
return False
|
||||
# Validate that /static/themes/<name>.css exists (works with collectstatic)
|
||||
try:
|
||||
return staticfiles_storage.exists(f"themes/{name}.css")
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def set_theme(request):
|
||||
if request.method != 'POST':
|
||||
return HttpResponseBadRequest('Invalid method')
|
||||
theme = (request.POST.get('theme') or '').strip()
|
||||
theme = (request.POST.get("theme") or "").strip()
|
||||
if not theme:
|
||||
messages.error(request, "Pick a theme first.")
|
||||
return redirect("settings_home")
|
||||
|
||||
if not _is_valid_theme(theme):
|
||||
return HttpResponseBadRequest('Unknown theme')
|
||||
request.session['theme'] = theme
|
||||
# also write to localStorage on next load via inline script in base.html
|
||||
# redirect back to settings
|
||||
return HttpResponseRedirect(reverse('settings')) # adjust to your settings view name/URL
|
||||
messages.error(
|
||||
request,
|
||||
f"Theme “{theme}” not found. Make sure /static/themes/{theme}.css exists (and run collectstatic in production)."
|
||||
)
|
||||
return redirect("settings_home")
|
||||
|
||||
request.session["theme"] = theme
|
||||
messages.success(request, f"Theme set to {theme.title()}.")
|
||||
return redirect("settings_home")
|
||||
Loading…
Reference in New Issue
Block a user