from django.shortcuts import render, redirect
from .models import Achievement, Proposal
from .forms import ProposalForm

def index(request):
    achievements = Achievement.objects.order_by('-date')[:6]
    context = {
        'achievements': achievements
    }
    return render(request, "core/index.html", context)

def submit_proposal(request):
    if request.method == 'POST':
        form = ProposalForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect('proposal_success')
    else:
        form = ProposalForm()
    
    context = {
        'form': form
    }
    return render(request, 'core/submit_proposal.html', context)

def proposal_success(request):
    return render(request, 'core/proposal_success.html')