DEBUG = True
TITLE = u"Cavote FFDN"
EMAIL = '"' + TITLE + '"' + ' <' + u"cavote@ffdn.org" + '>'
-BASEURL = "http://localhost:5000"
+BASEURL = "http://localhost:5000" # :TODO:maethor:120605: Find a cleaner way to do this
VERSION = "cavote 0.0.1"
SMTP_SERVER = "10.33.33.30"
-PATTERNS = {u'Oui/Non': [u'Oui', u'Non'], u'Oui/Non/Peut-être': [u'Oui', u'Non', u'Peut-être']}
+PATTERNS = {u'Oui/Non': [u'Oui', u'Non'], u'Oui/Non/Blanc': [u'Oui', u'Non', u'Blanc'], u'Oui/Non/Peut-être': [u'Oui', u'Non', u'Peut-être']}
app = Flask(__name__)
app.config.from_object(__name__)
def admin_groups():
if not session.get('user').get('is_admin'):
abort(401)
- groups = query_db('select * from groups')
+ groups = query_db('select groups.*, count(user_group.id_user) as nb_users from (select groups.*, count(votes.id) as nb_votes from groups left join votes on votes.id_group = groups.id group by groups.id) as groups left join user_group on user_group.id_group = groups.id group by groups.id')
return render_template('admin_groups.html', groups=groups)
@app.route('/admin/groups/add', methods=['POST'])
today = date.today()
active_button = votes
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'
+ basequery = 'select votes.*, max_votes from votes left 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 + ') 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'
for vote in votes:
if not vote.get('nb_votes'):
vote['nb_votes'] = 0
- vote['percent'] = int((float(vote['nb_votes']) / float(vote['max_votes'])) * 100)
+ if vote.get('max_votes'):
+ vote['percent'] = int((float(vote['nb_votes']) / float(vote['max_votes'])) * 100)
return render_template('votes.html', votes=votes, active_button=active_button)
#------
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
+ vote['nb_votes'] = 0
else:
vote['nb_votes'] = tmp['nb']
vote['percent'] = int((float(vote['nb_votes']) / float(vote['max_votes'])) * 100)
+ # :TODO:maethor:120606: Flash if user is concerned by the vote
return render_template('vote.html', vote=vote, attachments=attachments, choices=choices, users=users.values(), can_vote=can_vote(idvote, get_userid()))
flash(u'Vous n\'avez pas le droit de voir ce vote, désolé.')
return redirect(url_for('home'))