from django.contrib.auth.decorators import login_required from django.shortcuts import render from contacts.models import Contact from leads.models import Lead from messaging.models import Campaign from social.models import SocialPost @login_required def home(request): upcoming = Campaign.objects.exclude( status__in=[Campaign.Status.COMPLETED, Campaign.Status.CANCELLED] ).order_by("scheduled_for", "-created_at")[:5] context = { "lead_count": Lead.objects.filter(status=Lead.Status.NEW).count(), "open_pipeline": Lead.objects.filter( status__in=[Lead.Status.NEW, Lead.Status.CONTACTED] ).count(), "contact_count": Contact.objects.count(), "scheduled_posts": SocialPost.objects.filter( status__in=[SocialPost.Status.SCHEDULED, SocialPost.Status.QUEUED] ).count(), "recent_leads": Lead.objects.select_related("contact", "attribution").all()[:8], "upcoming_campaigns": upcoming, } return render(request, "dashboard/home.html", context)