2026-11-16 12:00:57 +01:00
|
|
|
from django.db import connection
|
|
|
|
|
from django.http import HttpResponse, JsonResponse
|
|
|
|
|
from django.shortcuts import render
|
2026-11-16 14:07:45 +01:00
|
|
|
from django.views.decorators.cache import never_cache
|
2026-11-16 12:00:57 +01:00
|
|
|
|
2026-11-16 14:19:56 +01:00
|
|
|
from apps.lottery.status import public_state
|
2026-11-16 12:00:57 +01:00
|
|
|
|
2026-11-16 14:19:56 +01:00
|
|
|
|
|
|
|
|
@never_cache
|
2026-11-16 12:00:57 +01:00
|
|
|
def home(request):
|
2026-11-16 14:19:56 +01:00
|
|
|
"""The public home (WEB-10): the state is rendered by the server, so the page works without JavaScript;
|
|
|
|
|
`home.js` then keeps the countdown and polls `state` (WEB-05)."""
|
|
|
|
|
return render(request, "web/home.html", {"s": public_state()})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@never_cache
|
|
|
|
|
def state(request):
|
|
|
|
|
"""The same state as JSON, public and never cached: what the home page polls (WEB-05, WEB-10)."""
|
|
|
|
|
return JsonResponse(public_state())
|
2026-11-16 12:00:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def health_live(request):
|
|
|
|
|
"""Liveness for the container healthcheck: the process answers and the database opens (ARC-73)."""
|
|
|
|
|
try:
|
|
|
|
|
with connection.cursor() as cursor:
|
|
|
|
|
cursor.execute("SELECT 1")
|
|
|
|
|
except Exception:
|
|
|
|
|
return HttpResponse("database unavailable", status=503, content_type="text/plain")
|
|
|
|
|
return JsonResponse({"status": "ok"})
|
2026-11-16 14:07:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Error pages in Italian, in the site's own layout, with a way out (WEB-06).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def csrf_failure(request, reason=""):
|
|
|
|
|
return render(request, "web/error.html", {
|
|
|
|
|
"title": "Sessione scaduta",
|
|
|
|
|
"message": "Il modulo non è più valido, probabilmente perché la pagina è rimasta aperta a lungo. "
|
|
|
|
|
"Ricarica la pagina e riprova.",
|
|
|
|
|
}, status=403)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def not_found(request, exception=None):
|
|
|
|
|
return render(request, "web/error.html", {
|
|
|
|
|
"title": "Pagina non trovata", "message": "L'indirizzo richiesto non esiste.",
|
|
|
|
|
}, status=404)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def server_error(request):
|
|
|
|
|
return render(request, "web/error.html", {
|
|
|
|
|
"title": "Qualcosa è andato storto",
|
|
|
|
|
"message": "Si è verificato un errore. Riprova fra qualche istante.",
|
|
|
|
|
}, status=500)
|