anna-dan-wedding-site/bigday/views.py

37 lines
1.2 KiB
Python
Raw Normal View History

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':
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()
if any_attending:
return redirect('thanks')
else:
return redirect('sorry')
2019-08-06 23:51:28 +00:00
def thanks(request):
return render(request, 'thank-you.html', {'attending': True})
def sorry(request):
return render(request, 'thank-you.html', {'attending': False})