|
@@ -298,9 +298,13 @@ def votes(votes):
|
|
|
if votes == 'all':
|
|
|
votes = query_db(basequery + ' order by id desc')
|
|
|
elif votes == 'archive':
|
|
|
- votes = query_db(basequery + ' and date_end < (?) order by id desc', [today])
|
|
|
+ votes = query_db(basequery + ' and is_terminated=1 order by id desc')
|
|
|
elif votes == 'current':
|
|
|
- votes = query_db(basequery + ' and date_end >= (?) order by id desc', [today])
|
|
|
+ votes = query_db(basequery + ' and is_terminated=0 order by id desc')
|
|
|
+ elif votes == 'waiting':
|
|
|
+ basequery = 'select votes.* from user_group join (' + basequery + ') as votes on votes.id_group = user_group.id_group where user_group.id_user = ?'
|
|
|
+ already_voted = 'select id_vote from user_choice join choices on user_choice.id_choice = choices.id where id_user = ?'
|
|
|
+ votes = query_db(basequery + ' and votes.id not in (' + already_voted + ') and is_terminated=0', [get_userid(), get_userid()])
|
|
|
else:
|
|
|
abort(404)
|
|
|
for vote in votes:
|
|
@@ -322,17 +326,16 @@ def can_see_vote(idvote, iduser=-1):
|
|
|
return False
|
|
|
return True
|
|
|
|
|
|
-
|
|
|
-
|
|
|
def can_vote(idvote, iduser=-1):
|
|
|
vote = query_db('select * from votes where id=?', [idvote], one=True)
|
|
|
if vote is None:
|
|
|
return False
|
|
|
- if iduser > 0:
|
|
|
- if can_see_vote(idvote, iduser):
|
|
|
- if not has_voted(idvote, iduser):
|
|
|
- if query_db('select * from user_group where id_user = ? and id_group = ?', [iduser, vote['id']], one=True):
|
|
|
- return True
|
|
|
+ if not vote['is_finished']:
|
|
|
+ if iduser > 0:
|
|
|
+ if can_see_vote(idvote, iduser):
|
|
|
+ if not has_voted(idvote, iduser):
|
|
|
+ if query_db('select * from user_group where id_user = ? and id_group = ?', [iduser, vote['id']], one=True):
|
|
|
+ return True
|
|
|
return False
|
|
|
|
|
|
def has_voted(idvote, iduser=-1):
|
|
@@ -459,14 +462,19 @@ def admin_vote_edit(voteid):
|
|
|
if 'public' in request.form.keys():
|
|
|
public = 1
|
|
|
isopen = 0
|
|
|
+ isterminated = 0
|
|
|
if request.form['status'] == 'Ouvert':
|
|
|
choices = query_db('select id_vote, count(*) as nb from choices where id_vote = ? group by id_vote', [voteid], one=True)
|
|
|
if choices is not None and choices['nb'] >= 2:
|
|
|
isopen = 1
|
|
|
else:
|
|
|
flash(u'Vous devez proposer au moins deux choix pour ouvrir le vote.', 'error')
|
|
|
- g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ? where id = ?',
|
|
|
- [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, voteid])
|
|
|
+ elif request.form['status'] == u'Terminé':
|
|
|
+ isterminated = 1
|
|
|
+ if vote['is_open']:
|
|
|
+ isopen = 1
|
|
|
+ g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ?, is_terminated = ? where id = ?',
|
|
|
+ [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, isterminated, voteid])
|
|
|
g.db.commit()
|
|
|
vote = query_db('select * from votes where id = ?', [voteid], one=True)
|
|
|
flash(u"Le vote a bien été mis à jour.", "success")
|