2019-08-06 23:51:28 +00:00
|
|
|
from django.shortcuts import render, redirect
|
2019-08-07 02:08:13 +00:00
|
|
|
from django.urls import reverse
|
2019-08-06 23:51:28 +00:00
|
|
|
|
|
|
|
from .models import InvitedGuest
|
|
|
|
|
|
|
|
def index(request):
|
|
|
|
return render(request, 'index.html')
|
|
|
|
|
2019-08-07 02:08:13 +00:00
|
|
|
def try_again(request):
|
|
|
|
return render(request, 'index.html', {'invalid_code': True})
|
|
|
|
|
2019-08-06 23:51:28 +00:00
|
|
|
def rsvp(request):
|
|
|
|
rsvpCode = request.GET['rsvp-code']
|
|
|
|
guests = InvitedGuest.objects.filter(rsvpCode = rsvpCode)
|
|
|
|
if request.method == 'GET':
|
2019-08-07 01:53:16 +00:00
|
|
|
if not guests:
|
|
|
|
# No guests with that code
|
2019-08-07 02:08:13 +00:00
|
|
|
return redirect(reverse('try-again') + '#rsvp')
|
2019-08-06 23:51:28 +00:00
|
|
|
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()
|
2019-08-07 01:58:35 +00:00
|
|
|
if any_attending:
|
|
|
|
return redirect('thanks')
|
|
|
|
else:
|
|
|
|
return redirect('sorry')
|
2019-08-06 23:51:28 +00:00
|
|
|
|
|
|
|
def thanks(request):
|
2019-08-07 01:58:35 +00:00
|
|
|
return render(request, 'thank-you.html', {'attending': True})
|
|
|
|
|
|
|
|
def sorry(request):
|
|
|
|
return render(request, 'thank-you.html', {'attending': False})
|