From: Guillaume Subiron Date: Mon, 4 Jun 2012 17:58:21 +0000 (+0200) Subject: Progress bars X-Git-Url: http://git.cyclocoop.org/?p=cavote.git;a=commitdiff_plain;h=df5ece768e1f6197ca618c89490563e0420fce9d Progress bars --- diff --git a/main.py b/main.py index 74cb0f5..bb092ac 100755 --- a/main.py +++ b/main.py @@ -290,7 +290,11 @@ def admin_group_del(idgroup): def votes(votes): today = date.today() active_button = votes - basequery = 'select *, votes.id as voteid, groups.name as groupname from votes join groups on groups.id = id_group where is_open=1' + max_votes ='select id_group, count(*) as max_votes from user_group group by id_group' + basequery = 'select votes.*, max_votes from votes join (' + max_votes + ') as max_votes on votes.id_group = max_votes.id_group' + nb_votes = 'select id_vote, count(*) as nb_votes from (select id_user, id_vote from user_choice join choices on id_choice = choices.id group by id_user, id_vote) group by id_vote' + basequery = 'select * from (' + basequery + ') 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' if votes == 'all': votes = query_db(basequery + ' order by id desc') elif votes == 'archive': @@ -299,6 +303,8 @@ def votes(votes): votes = query_db(basequery + ' and date_end >= (?) order by id desc', [today]) else: abort(404) + for vote in votes: + vote['percent'] = int((float(vote['nb_votes']) / float(vote['max_votes'])) * 100) return render_template('votes.html', votes=votes, active_button=active_button) #------ @@ -355,6 +361,17 @@ def vote(idvote): users[t['userid']]['choices'] = [t['choiceid']] choices = query_db('select choices.name, choices.id, choices.name, choices.id_vote, count(id_choice) as nb from choices left join user_choice on id_choice = choices.id where id_vote = ? group by id_choice, name, id_vote order by id', [idvote]) attachments = query_db('select * from attachments where id_vote=?', [idvote]) + tmp = query_db('select id_group, count(*) as nb from user_group where id_group = ? group by id_group', [vote['id_group']], one=True) + if tmp is None: + vote['percent'] = 0 + else: + vote['max_votes'] = tmp['nb'] + tmp = query_db('select id_vote, count(*) as nb from (select id_user, id_vote from user_choice join choices on id_choice = choices.id group by id_user, id_vote) where id_vote = ? group by id_vote', [idvote], one=True) + if tmp is None: + vote['percent'] = 0 + else: + vote['nb_votes'] = tmp['nb'] + vote['percent'] = int((float(vote['nb_votes']) / float(vote['max_votes'])) * 100) return render_template('vote.html', vote=vote, attachments=attachments, choices=choices, users=users.values(), can_vote=can_vote(idvote, get_userid())) flash('Vous n\'avez pas le droit de voir ce vote, désolé.') return(url_for('home')) diff --git a/templates/vote.html b/templates/vote.html index b6ea499..86b020d 100644 --- a/templates/vote.html +++ b/templates/vote.html @@ -3,7 +3,6 @@
- {% if not vote.is_transparent %}
Ce sondage n'est pas transparent, vous ne pouvez pas voir les votes des autres.
{% endif %} @@ -70,6 +69,10 @@

Informations

+Avancement : {{ vote.nb_votes }} / {{ vote.max_votes }} +
+
+
Publié par
maethor
Début le
{{ vote.date_begin }} diff --git a/templates/votes.html b/templates/votes.html index 55ab248..88ffee5 100644 --- a/templates/votes.html +++ b/templates/votes.html @@ -8,13 +8,13 @@ Liste des votes

{{ vote.title }}

-
-
+
+

Deadline : {{ vote.date_end }}

-

Groupe : {{ vote.group }}

+

Groupe : {{ vote.groupname }}

Categorie : {{ vote.category }}