Permalink
Browse files

Make /start do something useful.

Introduces the concept, initializes the session.
  • Loading branch information...
1 parent 100a4de commit 20063b56dbbc70daf5e332261641ff8e86c58851 @georgevreilly committed Feb 3, 2013
View
15 gae_flask_app/AdYouLation/handlers.py
@@ -2,8 +2,10 @@
from flask import render_template, current_app, url_for, redirect
from flask.ext.wtf import Form, TextField, RadioField, Required, Email
from gaesessions import get_current_session
+
import random
import logging
+import uuid
def create_playlist():
videos = current_app.videos
@@ -20,14 +22,16 @@ def get_choices_remaining(index=2):
def update_playlist():
(choices, remaining) = get_choices_remaining()
- session = get_current_session()
- session['playlist'] = remaining
+ get_current_session()['playlist'] = remaining
return (choices, remaining)
@AdYouLation.route('/start')
def start():
- choices, remaining = update_playlist()
- return render_template("start.html", choices=choices, remaining=remaining)
+ session = get_current_session()
+ session['playlist'] = create_playlist()
+ if not session.get('id'):
+ session['id'] = uuid.uuid4()
+ return render_template("start.html")
class VideoVote(RadioField):
CHOICES = (("UP", "Yes!"), ("down", "No!"))
@@ -46,8 +50,9 @@ class VoteForm(Form):
@AdYouLation.route('/vote', methods=('GET', 'POST'))
def vote():
choices, remaining = get_choices_remaining()
+ id = get_current_session()['id']
form = vote_form(choices)
if form.validate_on_submit():
update_playlist()
return redirect(url_for(".vote"))
- return render_template("vote.html", form=form, remaining=remaining)
+ return render_template("vote.html", form=form, remaining=remaining, id=id)
View
12 gae_flask_app/static/style.css
@@ -9,3 +9,15 @@ td.video-choice div {
margin-right: 30px;
padding: 10px;
}
+
+div.get-started {
+ width: 300px;
+ background-color: orange;
+ font-size: 2em;
+ padding-left: 2ex;
+ padding-right: 2ex;
+}
+
+div.get-started a {
+ text-decoration: none;
+}
View
26 gae_flask_app/templates/start.html
@@ -1,19 +1,13 @@
{% extends "layout.html" %}
{% block body %}
- <h1>Choices</h1>
- <ul class=choices>
- {% for video in choices %}
- <li><h2>{{ video }}</h2>
- {% else %}
- <li><em>Unbelievable. No entries here so far</em>
- {% endfor %}
- </ul>
- <h1>Remaining</h1>
- <ul class=remaining>
- {% for video in remaining %}
- <li><h2>{{ video }}</h2>
- {% else %}
- <li><em>Unbelievable. No entries here so far</em>
- {% endfor %}
- </ul>
+ <h1>Vote for Your Favorite Super Bowl Ads</h1>
+ <p>Vote on the best Superbowl Ad!
+ Predict the most popular ad!
+ Watch the Superbowl ads, choosing the ones you like the most,
+ then vote for the best of the lot by texting to our number.
+ See if you can predict the most popular ads!</p>
+
+ <div class="get-started">
+ <a href="{{ url_for('.vote') }}">Let's get started</a>
+ </div>
{% endblock %}
View
1 gae_flask_app/templates/vote.html
@@ -13,4 +13,5 @@
<input type="submit" value="Vote" class="button green">
</form>
<p>{{ remaining }}</p>
+ <p>ID: {{ id }}</p>
{% endblock %}

0 comments on commit 20063b5

Please sign in to comment.