Merge branch 'wrong-code' into 'master'

Show a message if the invitation code is wrong

See merge request VickySteeves/anna-dan-wedding-site!3
This commit is contained in:
Vicky Steeves 2019-08-07 02:11:55 +00:00
commit 3f44260e73
3 changed files with 14 additions and 0 deletions

View File

@ -108,6 +108,12 @@
<h2>RSVP</h2> <h2>RSVP</h2>
<p>Kindly let us know if you will be able to attend our wedding! On the back of your invitation should be a two-digit code. Please enter that in the box below, which will take you to a personalized RSVP form.</p> <p>Kindly let us know if you will be able to attend our wedding! On the back of your invitation should be a two-digit code. Please enter that in the box below, which will take you to a personalized RSVP form.</p>
{% if invalid_code %}
<div class="alert alert-danger" role="alert">
Sorry, this invitation code doesn't seem quite right...
</div>
{% endif %}
<form action="{% url 'rsvp' %}" method="get" class="form-inline justify-content-center"> <form action="{% url 'rsvp' %}" method="get" class="form-inline justify-content-center">
<label class="sr-only" for="rsvp-code">RSVP Code</label> <label class="sr-only" for="rsvp-code">RSVP Code</label>

View File

@ -1,14 +1,21 @@
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.urls import reverse
from .models import InvitedGuest from .models import InvitedGuest
def index(request): def index(request):
return render(request, 'index.html') return render(request, 'index.html')
def try_again(request):
return render(request, 'index.html', {'invalid_code': True})
def rsvp(request): def rsvp(request):
rsvpCode = request.GET['rsvp-code'] rsvpCode = request.GET['rsvp-code']
guests = InvitedGuest.objects.filter(rsvpCode = rsvpCode) guests = InvitedGuest.objects.filter(rsvpCode = rsvpCode)
if request.method == 'GET': if request.method == 'GET':
if not guests:
# No guests with that code
return redirect(reverse('try-again') + '#rsvp')
return render (request, 'rsvp.html', {'guests':guests, 'rsvpCode': rsvpCode}) return render (request, 'rsvp.html', {'guests':guests, 'rsvpCode': rsvpCode})
elif request.method == 'POST': elif request.method == 'POST':
any_attending = False any_attending = False

View File

@ -5,6 +5,7 @@ import bigday.views
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', bigday.views.index, name='index'), path('', bigday.views.index, name='index'),
path('try-again', bigday.views.try_again, name='try-again'),
path('rsvp',bigday.views.rsvp, name='rsvp'), path('rsvp',bigday.views.rsvp, name='rsvp'),
path('thanks', bigday.views.thanks, name='thanks'), path('thanks', bigday.views.thanks, name='thanks'),
path('sorry', bigday.views.sorry, name='sorry'), path('sorry', bigday.views.sorry, name='sorry'),