Permalink
Browse files

Two "videos" side-by-side

  • Loading branch information...
1 parent 6d5fce9 commit e1b6d2afe55e9cd08fc7e3a2d4cb26c3ad9d6b7f @georgevreilly committed Feb 3, 2013
@@ -3,6 +3,7 @@
from flask.ext.wtf import Form, TextField, RadioField, Required, Email
from gaesessions import get_current_session
import random
+import logging
def create_playlist():
videos = current_app.videos
@@ -24,17 +25,27 @@ def start():
choices, remaining = update_playlist()
return render_template("start.html", choices=choices, remaining=remaining)
-class VoteForm(Form):
+class VideoVote(RadioField):
CHOICES = (("UP", "Yes!"), ("down", "No!"))
- video1Vote = RadioField("video #1", choices=CHOICES)
- video2Vote = RadioField("video #2", choices=CHOICES)
+
+def vote_form(videos):
+ class VoteForm(Form):
+ pass
+
+ for index, video in enumerate(videos):
+ name = "video_{}".format(index+1)
+ field = VideoVote(video, validators=[Required()], choices=VideoVote.CHOICES)
+ setattr(VoteForm, name, field)
+
+ return VoteForm()
@AdYouLation.route('/vote', methods=('GET', 'POST'))
def vote():
- form = VoteForm()
+ choices, remaining = update_playlist()
+ form = vote_form(choices)
+ logging.info(dir(form))
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])
+ return render_template("vote.html", form=form)
@@ -2,3 +2,10 @@
border: 1px solid black;
padding: 10px;
}
+
+td.video-choice div {
+ width: 300px;
+ border-style: dotted;
+ margin-right: 30px;
+ padding: 10px;
+}
@@ -13,6 +13,7 @@
{% macro render_video(video) %}
<div class="video_field">
- <h4>{{ video }}</h4>
+ <h4>{{ video.label }}</h4>
+ {{ video(**kwargs) }}
</div>
{% endmacro %}
@@ -3,11 +3,12 @@
<h1>Vote</h1>
{% from "forms/macros.html" import render_field, render_video %}
<form method="POST" action="." class="form">
- {{ render_video(video1) }}
- {{ render_field(form.video1Vote) }}
- <br/>
- {{ render_video(video2) }}
- {{ render_field(form.video2Vote) }}
- <input type="submit" value="Vote" class="button green">
+ <table>
+ <tr>
+ <td class="video-choice">{{ render_video(form.video_1) }}</td>
+ <td class="video-choice">{{ render_video(form.video_2) }}</td>
+ </tr>
+ <table>
+ <input type="submit" value="Vote" class="button green">
</form>
{% endblock %}

0 comments on commit e1b6d2a

Please sign in to comment.