Implement RSVP
This commit is contained in:
parent
31526f41f3
commit
bcf8b39ec4
|
@ -4,19 +4,18 @@
|
|||
<title>RSVP - Vicky & Remi</title>
|
||||
</head>
|
||||
<body>
|
||||
{% if error %}
|
||||
<p class="error">{{ error }}</p>
|
||||
{% endif %}
|
||||
<form action="" method="POST">
|
||||
{% for person in adults %}
|
||||
<p>
|
||||
<input type="checkbox" name="{{ person }}" id="{{ person }}" />
|
||||
<label for="{{ person }}">{{ person }}</label>
|
||||
<label for="adults">Adultes :</label>
|
||||
<input type="number" name="adults" id="adults" min="1" max="5" />
|
||||
</p>
|
||||
{% endfor %}
|
||||
{% for person in kids %}
|
||||
<p>
|
||||
<input type="checkbox" name="{{ person }}" id="{{ person }}" />
|
||||
<label for="{{ person }}">{{ person }}</label>
|
||||
<label for="children">Enfants :</label>
|
||||
<input type="number" name="children" id="children" min="0" max="5" />
|
||||
</p>
|
||||
{% endfor %}
|
||||
<p><input type="submit" value="RSVP" /></p>
|
||||
</form>
|
||||
</body>
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
from flask import Flask, render_template, request, url_for
|
||||
import logging
|
||||
from werkzeug.utils import redirect
|
||||
|
||||
from .database import get_name_and_replies, record_reply
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = Flask('france_rsvp')
|
||||
|
||||
|
@ -26,16 +31,29 @@ def thanks():
|
|||
|
||||
@app.route('/france/<code>', methods=['GET', 'POST'])
|
||||
def rsvp(code):
|
||||
error = None
|
||||
if request.method == 'POST':
|
||||
# TODO: Store response
|
||||
return redirect(url_for('thanks'))
|
||||
try:
|
||||
adults = int(request.form['adults'], 10)
|
||||
children = int(request.form['children'], 10)
|
||||
except (KeyError, ValueError, OverflowError):
|
||||
logger.warning("Invalid reply", exc_info=True)
|
||||
error = "Nombres invalides"
|
||||
else:
|
||||
record_reply(code, adults, children)
|
||||
return redirect(url_for('thanks'))
|
||||
|
||||
# TODO: Lookup guest from code
|
||||
adults = ['Remi', 'Vicky']
|
||||
kids = ['LB']
|
||||
# Lookup guests from code
|
||||
adults = None
|
||||
kids = None
|
||||
try:
|
||||
name, adults, kids = get_name_and_replies(code)
|
||||
except ValueError:
|
||||
error = "Code invalide"
|
||||
|
||||
return render_template(
|
||||
'rsvp.html',
|
||||
adults=adults,
|
||||
kids=kids,
|
||||
error=error,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue