diff options
Diffstat (limited to 'wedding.py')
| -rw-r--r-- | wedding.py | 33 |
1 files changed, 20 insertions, 13 deletions
@@ -78,21 +78,28 @@ def rsvp(): db = get_db() update_string = [] args = [] - for k, v in request.form.items(): - update_string.append("{0}=?".format(k)) - if k in ["rsvp", "plusone", "kids"]: - ## convert to integer - args.append(int(v)) - else: + for k in ['full_name', 'email', 'mailing', 'plusonename', 'kidsnames', 'comments']: + v = request.form.get(k) + if v: + update_string.append("{0}=?".format(k)) + args.append(v) + for k in ["rsvp", "plusone", "kids"]: + v = request.form.get(k, type=int) + if v: + update_string.append("{0}=?".format(k)) args.append(v) - update_string = ",".join(update_string) - query = "UPDATE guests set {0} , lastupdate=current_timestamp " \ - "WHERE user_name=?".format(update_string) - with db: - db.execute(query, tuple(args+[session['user_name']])) - flash(gettext("We have updated your information!")) - return redirect(url_for('rsvp')) + if update_string: + update_string = ",".join(update_string) + query = "UPDATE guests set {0} , lastupdate=current_timestamp " \ + "WHERE user_name=?".format(update_string) + with db: + db.execute(query, tuple(args+[session['user_name']])) + flash(gettext("We have updated your information!")) + return redirect(url_for('rsvp')) + else: + flash(gettext("We could not update your information!")) + return redirect(url_for('rsvp')) @app.route('/') @app.route('/home/') |
