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':
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)
#------
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'))
<div class="row">
<div class="span9">
<h2 class='page-header'>{{ vote.title }}</h2>
-
{% if not vote.is_transparent %}
<div class="alert alert-info">Ce sondage n'est pas transparent, vous ne pouvez pas voir les votes des autres.</div>
{% endif %}
<div class="span3">
<h3>Informations</h3>
+<strong>Avancement : </strong> {{ vote.nb_votes }} / {{ vote.max_votes }}
+<div class="progress progress-striped {% if vote.nb_votes == vote.max_votes %}progress-success{% endif %}">
+ <div class="bar" style="width: {{ vote.percent }}%;"></div>
+</div>
<dl class="dl-horizontal">
<dt>Publié par <dd><code>maethor</code>
<dt>Début le <dd><code>{{ vote.date_begin }}</code>
<div class="row well">
<div class="span4">
<h3><a href="{{ url_for('vote', idvote=vote.voteid) }}">{{ vote.title }}</a></h3>
- <div class="progress progress-striped">
- <div class="bar" style="width: 60{{ vote.percent }}%;"></div>
+ <div class="progress progress-striped {% if vote.nb_votes == vote.max_votes %}progress-success{% endif %}">
+ <div class="bar" style="width: {{ vote.percent }}%;"></div>
</div>
</div>
<div class="span3">
<h4>Deadline : {{ vote.date_end }} </h4>
- <h4>Groupe : {{ vote.group }}</h4>
+ <h4>Groupe : {{ vote.groupname }}</h4>
<h4>Categorie : {{ vote.category }}</h4>
</div>
<div class="span3">