30 lines
966 B
Python
30 lines
966 B
Python
from django.shortcuts import render, redirect
|
|
|
|
from .models import InvitedGuest
|
|
|
|
def index(request):
|
|
return render(request, 'index.html')
|
|
|
|
def rsvp(request):
|
|
rsvpCode = request.GET['rsvp-code']
|
|
guests = InvitedGuest.objects.filter(rsvpCode = rsvpCode)
|
|
if request.method == 'GET':
|
|
return render (request, 'rsvp.html', {'guests':guests, 'rsvpCode': rsvpCode})
|
|
elif request.method == 'POST':
|
|
any_attending = False
|
|
for guest in guests:
|
|
attending = request.POST['attending_%d' % guest.id] == 'attending'
|
|
guest.attending = attending
|
|
any_attending = any_attending or attending
|
|
guest.save()
|
|
if any_attending:
|
|
return redirect('thanks')
|
|
else:
|
|
return redirect('sorry')
|
|
|
|
def thanks(request):
|
|
return render(request, 'thank-you.html', {'attending': True})
|
|
|
|
def sorry(request):
|
|
return render(request, 'thank-you.html', {'attending': False})
|