Permalink
Browse files

Record Votes

  • Loading branch information...
1 parent 21d723a commit fae053037258e703d5b4699925d90550785b7f61 @georgevreilly committed Feb 3, 2013
Showing with 16 additions and 3 deletions.
  1. +16 −3 gae_flask_app/AdYouLation/handlers.py
@@ -53,26 +53,39 @@ def start():
session['id'] = uuid.uuid4()
return render_template("start.html")
-class VideoVote(RadioField):
- CHOICES = (("UP", "Yes!"), ("down", "No!"))
+class VideoChoice(RadioField):
+ CHOICES = (("up", "Yes!"), ("down", "No!"))
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)
+ field = VideoChoice(video, validators=[Required()], choices=VideoChoice.CHOICES)
setattr(VoteForm, name, field)
return VoteForm()
+def record_vote(form):
+ for index in [1, 2]:
+ attrname = "video_{}".format(index)
+ name = getattr(form, attrname).label.text
+ data = getattr(form, attrname).data
+ vv = VideoVotes.gql("WHERE name = :1", name).get()
+ if data == "up":
+ vv.up_votes += 1
+ else:
+ vv.down_votes += 1
+ vv.put()
+
@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()
+ record_vote(form)
return redirect(url_for(".vote"))
return render_template("vote.html", form=form, remaining=remaining, id=id)

0 comments on commit fae0530

Please sign in to comment.