Browse files

Partially working voting form

  • Loading branch information...
1 parent 46ac456 commit f45b33d2e38226a4ab6813fd90c6f785bbc19ef9 @georgevreilly committed Feb 3, 2013
View
25 gae_flask_app/AdYouLation/handlers.py
@@ -1,5 +1,6 @@
from ..AdYouLation import AdYouLation
from flask import render_template, current_app
+from flask.ext.wtf import Form, TextField, RadioField, Required, Email
from gaesessions import get_current_session
import random
@@ -9,13 +10,31 @@ def create_playlist():
random.shuffle(keys)
return keys
-@AdYouLation.route('/start')
-def start():
+def update_playlist():
session = get_current_session()
playlist = session.get('playlist')
if not playlist:
playlist = create_playlist()
choices = playlist[:2]
session['playlist'] = remaining = playlist[2:]
-
+ return (choices, remaining)
+
+@AdYouLation.route('/start')
+def start():
+ choices, remaining = update_playlist()
return render_template("start.html", choices=choices, remaining=remaining)
+
+class VoteForm(Form):
+# Video1Vote = RadioField(choices=("Yes!", "No!"))
+# Video2Vote = RadioField(choices=("Win!", "Lose!"))
+ email = TextField('email address', [Required(), Email()])
+
+@AdYouLation.route('/vote', methods=('GET', 'POST'))
+def vote():
+ form = VoteForm()
+ if form.validate_on_submit():
+ flash("Success")
+ return redirect(url_for("start"))
+ else:
+ choices, remaining = update_playlist()
+ return render_template("vote.html", form=form, video1=choices[0], video2=choices[1])
View
1 gae_flask_app/settings.py
@@ -7,3 +7,4 @@ def hex_random(num_bytes):
VIDEO_JSON="test-videos.json"
COOKIE_KEY='0753e9465b8e5d2a0391dc3ef3f2e9a6ca14fc1bed63eae2c2101af80412de19c82553d532839495cc2b9e5db512d543dfb12cdbf9530c68fe9c57ced074c97a'
+SECRET_KEY='development key'
View
12 gae_flask_app/templates/forms/macros.html
@@ -0,0 +1,12 @@
+{% macro render_field(field) %}
+ <div class="form_field">
+ {{ field.label(class="label") }}
+ {% if field.errors %}
+ {% set css_class = 'has_error ' + kwargs.pop('class', '') %}
+ {{ field(class=css_class, **kwargs) }}
+ <ul class="errors">{% for name,error in field.errors.items() %}<li>{{ error|e }}</li>{% endfor %}</ul>
+ {% else %}
+ {{ field(**kwargs) }}
+ {% endif %}
+ </div>
+{% endmacro %}
View
12 gae_flask_app/templates/vote.html
@@ -0,0 +1,12 @@
+{% extends "layout.html" %}
+{% block body %}
+ <h1>Vote</h1>
+ {% from "forms/macros.html" import render_field %}
+ <form method="POST" action="." class="form">
+ {{ video1 }}
+ {{ render_field(form.email) }}
+ <br/>
+ {{ video2 }}
+ <input type="submit" value="Login" class="button green">
+ </form>
+{% endblock %}

0 comments on commit f45b33d

Please sign in to comment.