Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle production data, odd number of videos

  • Loading branch information...
commit c906938e5d2ac70e313441dbcdfdceaf82bfa60f 1 parent 97bf850
@georgevreilly authored
View
20 gae_flask_app/AdYouLation/handlers.py
@@ -74,14 +74,18 @@ class VideoChoice(RadioField):
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()
+ if hasattr(form, attrname):
+ attr = getattr(form, attrname)
+ name = attr.label.text
+ data = attr.data
+ vv = VideoVotes.gql("WHERE name = :1", name).get()
+ if not vv:
+ vv = VideoVotes(name=name, up_votes=0, down_votes=0)
+ if data == "up":
+ vv.up_votes += 1
+ else:
+ vv.down_votes += 1
+ vv.put()
@AdYouLation.route('/vote', methods=('GET', 'POST'))
def vote():
View
2  gae_flask_app/settings.py
@@ -4,7 +4,7 @@ def hex_random(num_bytes):
return binascii.b2a_hex(os.urandom(num_bytes))
DEBUG=True # True => Security Hole
-VIDEO_JSON="test-videos.json"
+VIDEO_JSON="videos.json"
COOKIE_KEY='0753e9465b8e5d2a0391dc3ef3f2e9a6ca14fc1bed63eae2c2101af80412de19c82553d532839495cc2b9e5db512d543dfb12cdbf9530c68fe9c57ced074c97a'
SECRET_KEY='development key'
View
2  gae_flask_app/templates/vote.html
@@ -7,7 +7,9 @@
<table>
<tr>
<td class="video-choice">{{ render_video(form.video_1) }}</td>
+ {% if form.video_2 %}
<td class="video-choice">{{ render_video(form.video_2) }}</td>
+ {% endif %}
</tr>
<table>
<input type="submit" value="Vote" class="button green">
Please sign in to comment.
Something went wrong with that request. Please try again.