diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2015-03-21 23:26:44 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2015-03-21 23:26:44 -0400 |
| commit | 508e68ccfccc606b0ea3f4f68e03cbc2377e9443 (patch) | |
| tree | a2ea3e4c7322d4f6efd502e9817ee8b03b882460 | |
| parent | e9c28b973b450e88d1536ab0886d2a52fdc6e6a1 (diff) | |
| download | wedding-website-508e68ccfccc606b0ea3f4f68e03cbc2377e9443.tar.gz | |
form's logic almost working
| -rw-r--r-- | static/wedding.js | 2 | ||||
| -rw-r--r-- | templates/en/rsvp.htm | 10 | ||||
| -rw-r--r-- | wedding.py | 44 |
3 files changed, 26 insertions, 30 deletions
diff --git a/static/wedding.js b/static/wedding.js index 015bc83..492c346 100644 --- a/static/wedding.js +++ b/static/wedding.js @@ -24,7 +24,7 @@ $("input:radio[name=language]").change(function(){ $("button[name=login]").text("Login"); } }); -$("input:radio[name=answer]").change(function(){ +$("input:radio[name=rsvp]").change(function(){ var state = $(this).val()=="0"; ["email", "mailing", "plusoneyes", "plusoneno", "kidsyes","kidsno"]. forEach(function(id){ diff --git a/templates/en/rsvp.htm b/templates/en/rsvp.htm index 5d10456..b190ffc 100644 --- a/templates/en/rsvp.htm +++ b/templates/en/rsvp.htm @@ -23,21 +23,21 @@ <label for="fullname" class="col-md-2 control-label">Full Name:</label> <div class="col-md-5"> <input type="text" id="fullname" class="form-control" - name="fullname" placeholder="Your full name" value="{{form['full_name'] if form['full_name']}}"/> + name="full_name" placeholder="Your full name" value="{{form['full_name'] if form['full_name']}}"/> </div> </div> <p style="text-indent:3em"> Will you be able to make it to our wedding? </p> <div class="form-group"> - <label for="answer" class="col-md-2 control-label">RSVP:</label> + <label for="rsvp" class="col-md-2 control-label">RSVP:</label> <div class="col-md-9"> <label class="radio-inline"> - <input type="radio" value="1" name="answer" + <input type="radio" value="1" name="rsvp" {%if form['rsvp'] %}checked {% endif %}>Yes </label> <label class="radio-inline"> - <input type="radio" value="0" name="answer" + <input type="radio" value="0" name="rsvp" {%if not form['rsvp'] %}checked {% endif %}>No </label> </div> @@ -122,7 +122,7 @@ </div> <div class="form-group"> <div class="col-md-offset-2 col-md-5"> - <button type="submit" class="btn btn-primary" name="rsvp"> + <button type="submit" class="btn btn-primary"> Update </button> </div> @@ -66,21 +66,20 @@ def rsvp(): form=r) if request.method == 'POST': db = get_db() - args = (request.form["fullname"], - int(request.form["answer"]), - request.form["email"], - request.form["mailing"], - int(request.form["plusone"]), - request.form["plusonename"], - int(request.form["kids"]), - request.form["kidsnames"], - request.form["comments"], - session["user_name"]) - cur = db.execute("""UPDATE guests set full_name=?, - rsvp=?, email=?, mailing=?, plusone=?, plusonename=?, kids=?, - kidsnames=?, comments=? WHERE user_name=?""", args) - db.commit() - cur.close() + f = defaultdict(str) + 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: + args.append(v) + update_string = ",".join(update_string) + query = "UPDATE guests set %s WHERE user_name=?" % update_string + with db: + db.execute(query, tuple(args+[session['user_name']])) flash("We have updated your information!") return redirect(url_for('rsvp')) @@ -106,15 +105,12 @@ def login(): error = None if request.method == 'POST': db = get_db() - c = db.cursor() - c.execute("SELECT * from guests where user_name=?", - (request.form['username'],)) - if not c.fetchone(): - c.close() - flash(wn[request.form['language']]) - return redirect(url_for('login')) - else: - c.close() + with db: + db.execute("SELECT * from guests where user_name=?", + (request.form['username'],)) + if not db.fetchone(): + flash(wn[request.form['language']]) + return redirect(url_for('login')) if request.form['password'] != app.config['PASSWORD']: flash(wp[request.form['language']]) return redirect(url_for('login')) |
