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

24 lines
926 B
Python
Raw Normal View History

2019-08-06 23:51:28 +00:00
from django.shortcuts import render, redirect
from django.urls import reverse
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()
return redirect(reverse('thank-you') + '?attending=' + ('yes' if any_attending else 'no'))
def thanks(request):
return render(request, 'thank-you.html', {'attending': request.GET.get('attending') == 'yes'})