from django.shortcuts import render, get_object_or_404
from .models import Event, School

def home(request):
    """Render the landing screen with upcoming events."""
    events = Event.objects.filter(is_published=True).order_by('start_date')[:6]
    schools = School.objects.all()
    
    context = {
        "events": events,
        "schools": schools,
    }
    return render(request, "core/index.html", context)

def event_detail(request, event_id):
    """Render the detailed view for a specific school event."""
    event = get_object_or_404(Event, id=event_id)
    return render(request, "core/event_detail.html", {"event": event})