fix cardinal-5 description
[cavote.git] / main.py
diff --git a/main.py b/main.py
index 8093465..14a839b 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -344,7 +344,7 @@ def admin_user_edit(iduser):
                         g.db.execute('delete from user_group where id_user = ? and id_group = ?', [iduser, group['id']])
                         g.db.commit()
                 for group in groups:
-                    group = query_db('select id from groups where id = ?', group, one=True)
+                    group = query_db('select id from groups where id = ?', [group], one=True)
                     if group is None:
                         flash(u'Le groupe portant l\'id %s n\'existe pas.' % group, 'warning')
                     else:
@@ -432,9 +432,9 @@ def votes(votes):
                  left join (' + nb_votes + ') on id = id_vote'
     basequery = 'select *, votes.id as voteid, groups.name as groupname from (' + basequery + ') as votes \
                  join groups on groups.id = id_group \
-                 where is_open=1 and is_hidden=0'
+                 where is_hidden=0'
     if votes == 'all':
-        votes = query_db(basequery + ' order by date_end')
+        votes = query_db(basequery + ' and is_open=1 order by date_end')
     elif votes == 'archive':
         votes = query_db(basequery + ' and is_terminated=1 order by date_end desc')
     elif votes == 'current':
@@ -542,6 +542,7 @@ def vote(idvote):
                               group by id_group', [vote['id_group']], one=True)
         if max_votes is None:
             vote['percent'] = 0
+            vote['nb_votes'] = 0
         else:
             vote['max_votes'] = max_votes['nb']
             votes = query_db('select id_vote, count(*) as nb \
@@ -707,7 +708,7 @@ def admin_vote_add():
                     cardinal_values = cardinals[cardinal]['values']
                     weight = cardinals[cardinal]['first'] if not cardinals[cardinal]['first'] is None else -(cardinal/2)
                     if query_db('select * from cardinals where id = ?', [cardinal], one=True) is None:
-                        g.db.execute('insert into cardinals (id, name) values (?, ?)', [len(cardinal_values), cardinal_name])
+                        g.db.execute('insert into cardinals (id, name, first) values (?, ?, ?)', [len(cardinal_values), cardinal_name, weight])
                         g.db.commit()
                         for name in cardinal_values:
                             g.db.execute('insert into values_ (id_cardinal, name, weight) values (?, ?, ?)'
@@ -750,6 +751,7 @@ def admin_vote_edit(voteid):
     vote = query_db('select * from votes where id = ?', [voteid], one=True)
     if vote is None:
         abort(404)
+    print "\nvote: %s\n" % str(vote)
     if request.method == 'POST':
         if request.form['title']:
             if request.form['days'] > 0:
@@ -815,7 +817,7 @@ def admin_vote_edit(voteid):
     choices = query_db('select * from choices where id_vote = ?', [voteid])
     values_ = query_db('select * from cardinals where id = ?', [vote['id_cardinal']], one=True)['name']
     attachments = query_db('select * from attachments where id_vote = ?', [voteid])
-    if date.today().strftime("%Y-%m-%d") > vote['date_end']:
+    if date.today().strftime("%Y-%m-%d") > vote['date_end'] and not vote['is_terminated']:
         flash(u'La deadline du vote est expirée, vous devriez terminer le vote.')
     return render_template('admin_vote_edit.html', vote=vote, group=group, values_=values_, choices=choices, attachments=attachments, quorums=QUORUMS)