From e3913800e8bccbdc364b7f54d28a8d8efcfa2e1b Mon Sep 17 00:00:00 2001 From: Guillaume Subiron Date: Tue, 5 Jun 2012 11:58:16 +0200 Subject: [PATCH] Users can see waiting votes, votes can be terminated --- main.py | 30 +++++++++++++++++++----------- schema.sql | 5 +++-- templates/admin_vote_edit.html | 21 ++++++++++++++++----- templates/admin_votes.html | 2 +- templates/layout.html | 2 +- templates/vote.html | 8 +++++++- templates/votes.html | 4 ++-- 7 files changed, 49 insertions(+), 23 deletions(-) diff --git a/main.py b/main.py index e86e453..22d8c87 100755 --- a/main.py +++ b/main.py @@ -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") diff --git a/schema.sql b/schema.sql index 7f6a0bc..541fa23 100644 --- a/schema.sql +++ b/schema.sql @@ -18,7 +18,7 @@ create table users ( create table groups ( id INTEGER primary key autoincrement, - name TEXT, + name TEXT unique not null, system INTEGER default 0 not null ); @@ -42,6 +42,7 @@ create table votes ( is_multiplechoice INTEGER default 1 not null, is_weighted INTEGER default 0 not null, is_open INTEGER default 0 not null, + is_terminated INTEGER default 0 not null, id_author INTEGER, -- :COMMENT:maethor:120528: not null ? id_group INTEGER default 1 not null, FOREIGN KEY(id_author) REFERENCES users(id) @@ -76,5 +77,5 @@ create table user_choice ( insert into users (email, password, name, organization, is_admin, key) values ("admin@admin.fr", "d033e22ae348aeb5660fc2140aec35850c4da997", "Toto (admin) Tata", "World corp", 1, "test"); -- mdp = admin insert into groups (id, name, system) values (1, "Tous", 1); insert into groups (name) values ("CA"); -insert into groups (name) values ("Members"); +insert into groups (name) values ("Membres"); diff --git a/templates/admin_vote_edit.html b/templates/admin_vote_edit.html index d2f4ac1..a0adb07 100644 --- a/templates/admin_vote_edit.html +++ b/templates/admin_vote_edit.html @@ -75,10 +75,12 @@ Le vote est-il visible par tous ? + {% if not vote.is_terminated == 1 %} + {% endif %} @@ -89,12 +91,19 @@
@@ -107,6 +116,7 @@ + {% if not vote.is_terminated == 1%}
Choix @@ -138,6 +148,7 @@
+ {% endif %}
Pièces jointes diff --git a/templates/admin_votes.html b/templates/admin_votes.html index 786cec3..e3faf72 100644 --- a/templates/admin_votes.html +++ b/templates/admin_votes.html @@ -22,7 +22,7 @@ {% for vote in votes %} {{ vote.title }} - {% if vote.is_open %}Ouvert{% else %}Fermé{% endif %} + {% if vote.is_terminated %}Terminé{% else %}{% if vote.is_open %}Ouvert{% else %}Fermé{% endif %}{% endif %} {{ vote.date_end }} {{ vote.groupname }} {{ vote.category }} diff --git a/templates/layout.html b/templates/layout.html index 321610b..6fe38aa 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -41,7 +41,7 @@ {{ session.user.name }}
{% else %}
Il n'y a pas encore de votes. Désolé.
{% endfor %} -- 2.20.1