Debug
authorGuillaume Subiron <maethor@subiron.org>
Tue, 5 Jun 2012 14:36:09 +0000 (16:36 +0200)
committerJulien Rabier <taziden@flexiden.org>
Tue, 5 Jun 2012 17:41:17 +0000 (19:41 +0200)
main.py
templates/vote.html

diff --git a/main.py b/main.py
index 51af2a9..c276c37 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -89,7 +89,7 @@ def login():
     if request.method == 'POST':
         user = valid_login(request.form['username'], request.form['password'])
         if user is None:
-            flash('Email ou mot de passe invalide.', 'error')
+            flash(u'Email ou mot de passe invalide.', 'error')
         else:
             connect_user(user)
             flash(u'Vous êtes connecté. Bienvenue, %s !' % user['name'], 'success')
@@ -99,7 +99,7 @@ def login():
 @app.route('/logout')
 def logout():
     disconnect_user()
-    flash('Vous avez été déconnecté.', 'info')
+    flash(u'Vous avez été déconnecté.', 'info')
     return redirect(url_for('home'))
 
 #-----------------
@@ -362,7 +362,7 @@ def can_vote(idvote, iduser=-1):
     vote = query_db('select * from votes where id=?', [idvote], one=True)
     if vote is None:
         return False
-    if vote['is_finished'] == 0:
+    if vote['is_terminated'] == 0:
         if iduser > 0: 
             if can_see_vote(idvote, iduser): 
                 if not has_voted(idvote, iduser):
@@ -382,14 +382,18 @@ def vote(idvote):
     if can_see_vote(idvote, get_userid()):
         if request.method == 'POST':
             if can_vote(idvote, get_userid()):
-                choices = query_db('select name, id from choices where id_vote=?', [idvote])
-                for choice in choices:
-                    if str(choice['id']) in request.form.keys():
+                if vote['is_multiplechoice'] == 0:
+                    if query_db('select * from choices where id = ?', [request.form['choice']], one=True) is not None:
                         g.db.execute('insert into user_choice (id_user, id_choice) values (?, ?)', 
-                                [session.get('user').get('id'), choice['id']])
+                                [session.get('user').get('id'), request.form['choice']])
                         g.db.commit()
-                        if vote['is_multiplechoice'] == 0:
-                            break
+                else:
+                    choices = query_db('select name, id from choices where id_vote=?', [idvote])
+                    for choice in choices:
+                        if str(choice['id']) in request.form.keys():
+                            g.db.execute('insert into user_choice (id_user, id_choice) values (?, ?)', 
+                                    [session.get('user').get('id'), choice['id']])
+                            g.db.commit()
             else:
                 abort(401)
         tuples = query_db('select choiceid, choicename, users.id as userid, users.name as username from (select choices.id as choiceid, choices.name as choicename, id_user as userid from choices join user_choice on choices.id = user_choice.id_choice where id_vote = ?) join users on userid = users.id', [idvote])
index 8c0f3e1..44469ad 100644 (file)
       <th><input type='text' name="username" value='{{ session.user.name }}' disabled /></th>
       {% if vote.is_multiplechoice %}
       {% for choice in choices %}
-      <td><input type='checkbox' name="{{ choice.id }}" /></td>
+      <td><input type='checkbox' name="{{ choice.id }}" value="{{ choice.id }}" /></td>
       {% endfor %}
       {% else %}
       {% for choice in choices %}
-      <td><input type='radio' name="{{ choice.id }}" /></td>
+      <td><input type='radio' name="choice" value="{{ choice.id }}" /></td>
       {% endfor %}
       {% endif %}
       <td><input type="submit" class="btn btn-primary" value="OK" /></td>