|
@@ -16,6 +16,8 @@ import os
|
|
|
import hashlib
|
|
|
import smtplib
|
|
|
import string
|
|
|
+import re
|
|
|
+from collections import OrderedDict
|
|
|
|
|
|
from settings import *
|
|
|
|
|
@@ -95,8 +97,8 @@ def get_userid():
|
|
|
else:
|
|
|
return user.get('id')
|
|
|
|
|
|
+#@oid.loginhandler
|
|
|
@app.route('/login', methods=['GET', 'POST'])
|
|
|
-@oid.loginhandler
|
|
|
def login():
|
|
|
if request.method == 'POST':
|
|
|
user = valid_login(request.form['username'], request.form['password'])
|
|
@@ -113,7 +115,7 @@ def login():
|
|
|
return redirect(url_for('home'))
|
|
|
return render_template('login.html')
|
|
|
|
|
|
-@oid.after_login
|
|
|
+#@oid.after_login
|
|
|
def create_or_login(resp):
|
|
|
openid_url = resp.identity_url
|
|
|
user = query_db('select * from users where openid = ?', [openid_url], one=True)
|
|
@@ -250,7 +252,6 @@ def admin_users():
|
|
|
users[t['userid']]['username'] = t['username']
|
|
|
users[t['userid']]['is_admin'] = t['is_admin']
|
|
|
users[t['userid']]['groups'] = [t['groupname']]
|
|
|
-
|
|
|
return render_template('admin_users.html', users=users.values())
|
|
|
|
|
|
@app.route('/admin/users/add', methods=['GET', 'POST'])
|
|
@@ -263,7 +264,7 @@ def admin_user_add():
|
|
|
if request.form['username']:
|
|
|
if query_db('select * from users where name=?', [request.form['username']], one=True) is None:
|
|
|
admin = 0
|
|
|
- if 'admin' in request.form.keys():
|
|
|
+ if 'admin' in request.form:
|
|
|
admin = 1
|
|
|
key = 'v%s' % keygen()
|
|
|
g.db.execute('insert into users (email, openid, name, organization, password, is_admin, key) \
|
|
@@ -331,7 +332,7 @@ def admin_user_edit(iduser):
|
|
|
if query_db('select * from users where email=? and id!=?', [request.form['email'], iduser], one=True) is None:
|
|
|
if query_db('select * from users where name=? and id!=?', [request.form['name'], iduser], one=True) is None:
|
|
|
admin = 0
|
|
|
- if 'admin' in request.form.keys():
|
|
|
+ if 'admin' in request.form:
|
|
|
admin = 1
|
|
|
g.db.execute('update users set email = ?, name = ?, organization = ?, openid= ?, is_admin = ? where id = ?',
|
|
|
[request.form['email'], request.form['name'], request.form['organization'], request.form['openid'], admin, iduser])
|
|
@@ -424,8 +425,7 @@ def votes(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 \
|
|
|
+ from user_vote \
|
|
|
group by id_user, id_vote) \
|
|
|
group by id_vote'
|
|
|
basequery = 'select * from (' + basequery + ') \
|
|
@@ -443,8 +443,7 @@ def votes(votes):
|
|
|
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 \
|
|
|
+ already_voted = 'select id_vote from user_vote \
|
|
|
where id_user = ?'
|
|
|
votes = query_db(basequery + ' and votes.id not in (' + already_voted + ') and is_terminated=0', [get_userid(), get_userid()])
|
|
|
else:
|
|
@@ -482,8 +481,7 @@ def can_vote(idvote, iduser=-1):
|
|
|
return False
|
|
|
|
|
|
def has_voted(idvote, iduser=-1):
|
|
|
- vote = query_db('select * from user_choice \
|
|
|
- join choices on id_choice=choices.id \
|
|
|
+ vote = query_db('select * from user_vote \
|
|
|
where id_vote = ? and id_user = ?', [idvote, iduser], one=True)
|
|
|
return (vote is not None)
|
|
|
|
|
@@ -497,60 +495,151 @@ def vote(idvote):
|
|
|
abort(404)
|
|
|
if can_see_vote(idvote, get_userid()):
|
|
|
choices = query_db('select name, id from choices where id_vote=?', [idvote])
|
|
|
+ values = query_db('select weight,name from values_ where id_cardinal=? order by weight ASC', [vote['id_cardinal']])
|
|
|
+ values.insert(0, {'weight':None,'name':u'=X̄ (Pas d’Opinion)'})
|
|
|
+ for v in values:
|
|
|
+ v['class'] = "value_" + re.sub('[^a-zA-Z0-9-]', '_', v['name'])
|
|
|
+ weights = OrderedDict([(v['weight'], v) for v in values])
|
|
|
if request.method == 'POST':
|
|
|
if can_vote(idvote, get_userid()):
|
|
|
- if vote['is_multiplechoice'] == 0:
|
|
|
- choice = request.form['choice']
|
|
|
- if choice in [str(c['id']) for c in choices] \
|
|
|
- and query_db('select * from choices where id = ?', [choice], one=True) is not None:
|
|
|
- g.db.execute('insert into user_choice (id_user, id_choice) values (?, ?)',
|
|
|
- [session.get('user').get('id'), request.form['choice']])
|
|
|
- g.db.commit()
|
|
|
- else:
|
|
|
- for choice in choices:
|
|
|
- if str(choice['id']) in request.form.keys():
|
|
|
- g.db.execute('insert into user_choice (id_user, id_choice) values (?, ?)',
|
|
|
- [session.get('user').get('id'), choice['id']])
|
|
|
- g.db.commit()
|
|
|
+ userid = session.get('user').get('id') if not vote['is_anonymous'] else None
|
|
|
+ # ACTION: store user's choices
|
|
|
+ for choice in choices:
|
|
|
+ if choice['name'] is None:
|
|
|
+ continue
|
|
|
+ weight = request.form.get('value-'+str(choice['id']),None)
|
|
|
+ if weight is not None and len(weight) is 0:
|
|
|
+ weight = None
|
|
|
+ if weight is not None:
|
|
|
+ weight = int(weight)
|
|
|
+ g.db.execute('insert into user_choice (id_user, id_choice, id_cardinal, weight) \
|
|
|
+ values (?, ?, ?, ?)', [userid, choice['id'], vote['id_cardinal'], weight])
|
|
|
+ g.db.commit()
|
|
|
+ # ACTION: randomize storage when anonymous votes
|
|
|
+ if vote['is_anonymous']:
|
|
|
+ g.db.execute('delete from user_choice_buffer_anonymous')
|
|
|
+ g.db.execute('insert into user_choice_buffer_anonymous select * \
|
|
|
+ from user_choice where id_choice in (%s)'
|
|
|
+ % ','.join(['?'] * len(choices))
|
|
|
+ , tuple(c['id'] for c in choices))
|
|
|
+ g.db.execute('delete from user_choice where id_choice in (%s)'
|
|
|
+ % ','.join(['?'] * len(choices))
|
|
|
+ , tuple(c['id'] for c in choices))
|
|
|
+ g.db.execute('insert into user_choice select * \
|
|
|
+ from user_choice_buffer_anonymous \
|
|
|
+ order by random()')
|
|
|
+ g.db.execute('delete from user_choice_buffer_anonymous')
|
|
|
+ g.db.commit()
|
|
|
+ g.db.execute('insert into user_vote (id_user, id_vote) \
|
|
|
+ values (?, ?)'
|
|
|
+ , [session.get('user').get('id'), vote['id']])
|
|
|
+ g.db.commit()
|
|
|
else:
|
|
|
abort(401)
|
|
|
- tuples = query_db('select choiceid, choicename, users.id as userid, users.name as username \
|
|
|
- from (select choices.id as choiceid, choices.name as choicename, id_user as userid \
|
|
|
- from choices join user_choice on choices.id = user_choice.id_choice \
|
|
|
- where id_vote = ?) \
|
|
|
- join users on userid = users.id', [idvote])
|
|
|
- users = dict()
|
|
|
- for t in tuples:
|
|
|
- if t['userid'] in users:
|
|
|
- users[t['userid']]['choices'].append(t['choiceid'])
|
|
|
- else:
|
|
|
- users[t['userid']] = dict()
|
|
|
- users[t['userid']]['userid'] = t['userid']
|
|
|
- users[t['userid']]['username'] = t['username']
|
|
|
- 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:
|
|
|
+ # ACTION: count quorum numbers
|
|
|
+ max_votes = query_db('select id_group, count(*) as nb \
|
|
|
+ from user_group where id_group = ? \
|
|
|
+ group by id_group', [vote['id_group']], one=True)
|
|
|
+ if max_votes 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['max_votes'] = max_votes['nb']
|
|
|
+ votes = query_db('select id_vote, count(*) as nb \
|
|
|
+ from (select id_user, id_vote from user_vote \
|
|
|
+ group by id_user, id_vote) \
|
|
|
+ where id_vote = ? group by id_vote', [idvote], one=True)
|
|
|
+ if votes is None:
|
|
|
vote['percent'] = 0
|
|
|
vote['nb_votes'] = 0
|
|
|
else:
|
|
|
- vote['nb_votes'] = tmp['nb']
|
|
|
+ vote['nb_votes'] = votes['nb']
|
|
|
vote['percent'] = int((float(vote['nb_votes']) / float(vote['max_votes'])) * 100)
|
|
|
- if query_db('select * from user_group where id_group = ? and id_user = ?', [vote['id_group'], get_userid()], one=True) and not vote['is_terminated']:
|
|
|
+ # ACTION: query users' choices joined with users' identity if not anonymous
|
|
|
+ user_choices = query_db('select user_choice.id_user as userid, users.name as username, \
|
|
|
+ choices.id as choiceid, choices.name as choice_name, \
|
|
|
+ user_choice.weight as weight \
|
|
|
+ from choices \
|
|
|
+ join user_choice on choices.id = user_choice.id_choice \
|
|
|
+ left join users on userid = users.id \
|
|
|
+ left join user_vote on userid = user_vote.id_user and choices.id_vote = user_vote.id_vote \
|
|
|
+ where choices.id_vote = ? \
|
|
|
+ order by user_vote.date,choices.id', [idvote])
|
|
|
+ # ACTION: aggregate user choices per vote
|
|
|
+ vote['blank'] = 0
|
|
|
+ results = OrderedDict()
|
|
|
+ for c in choices:
|
|
|
+ choice_values = [(w, { 'nb':0
|
|
|
+ , 'idx':i
|
|
|
+ , 'name':weights[w]['name']
|
|
|
+ , 'class':weights[w]['class'] }
|
|
|
+ ) for (i,w) in enumerate(weights, start=0)]
|
|
|
+ choice_values = OrderedDict(choice_values)
|
|
|
+ results[c['id']] = { 'id':c['id']
|
|
|
+ , 'name':c['name']
|
|
|
+ , 'sum':0
|
|
|
+ , 'average':0.0
|
|
|
+ , 'nb':0
|
|
|
+ , 'blank':0
|
|
|
+ , 'values_':choice_values }
|
|
|
+ for uc in user_choices:
|
|
|
+ results[uc['choiceid']]['nb'] += 1
|
|
|
+ results[uc['choiceid']]['values_'][uc['weight']]['nb'] += 1
|
|
|
+ if uc['weight'] is None:
|
|
|
+ results[uc['choiceid']]['blank'] += 1
|
|
|
+ vote['blank'] += 1
|
|
|
+ else:
|
|
|
+ results[uc['choiceid']]['sum'] += uc['weight']
|
|
|
+ for c in results:
|
|
|
+ if results[c]['nb'] - results[c]['blank'] != 0:
|
|
|
+ results[c]['average'] = results[c]['average'] + (float(results[c]['sum']) / float(results[c]['nb'] - results[c]['blank']))
|
|
|
+ previous_percent = 0
|
|
|
+ for w in weights:
|
|
|
+ if results[c]['nb'] > 0:
|
|
|
+ percent = float(results[c]['values_'][w]['nb'] * 100) / results[c]['nb']
|
|
|
+ else:
|
|
|
+ percent = 0.
|
|
|
+ results[c]['values_'][w]['percent'] = percent
|
|
|
+ results[c]['values_'][w]['previous_percent'] = previous_percent
|
|
|
+ previous_percent += percent
|
|
|
+ results[c]['values_'] = results[c]['values_'].values()
|
|
|
+ results = sorted(results.values(), key=lambda c: c['average'], reverse=True)
|
|
|
+ len_results = len(results)
|
|
|
+ if len_results % 2 == 0:
|
|
|
+ medians = results[len_results/2-1:len_results/2+1]
|
|
|
+ else:
|
|
|
+ medians = [results[len_results/2]]
|
|
|
+ results = { 'list':results
|
|
|
+ , 'medians':[m['id'] for m in medians]
|
|
|
+ , 'average':sum([r['sum'] for r in results])/len_results }
|
|
|
+ # ACTION: list user results per user
|
|
|
+ users = OrderedDict()
|
|
|
+ if vote['is_anonymous']:
|
|
|
+ user_votes = query_db('select users.name, id_user as userid \
|
|
|
+ from user_vote \
|
|
|
+ join users on users.id = id_user where id_vote = ?', [idvote])
|
|
|
+ for uc in user_votes:
|
|
|
+ users[uc['userid']] = { 'username':uc['name']
|
|
|
+ , 'choices':{}
|
|
|
+ , 'userid':uc['userid'] }
|
|
|
+ else:
|
|
|
+ for uc in user_choices:
|
|
|
+ weight = uc['weight']
|
|
|
+ value = { 'weight':weight
|
|
|
+ , 'name':weights[weight]['name']
|
|
|
+ , 'class':weights[weight]['class'] }
|
|
|
+ if uc['userid'] in users:
|
|
|
+ users[uc['userid']]['choices'][uc['choiceid']] = value
|
|
|
+ else:
|
|
|
+ users[uc['userid']] = { 'userid':uc['userid']
|
|
|
+ , 'username':uc['username']
|
|
|
+ , 'choices':{uc['choiceid']:value} }
|
|
|
+ attachments = query_db('select * from attachments where id_vote=?', [idvote])
|
|
|
+ if query_db('select * from user_group where id_group = ? and id_user = ?'
|
|
|
+ , [vote['id_group'], get_userid()], one=True) and not vote['is_terminated']:
|
|
|
flash(u'Ce vote vous concerne !', 'info')
|
|
|
- return render_template('vote.html', vote=vote, attachments=attachments, choices=choices, users=users.values(), can_vote=can_vote(idvote, get_userid()))
|
|
|
+ return render_template('vote.html', vote=vote, attachments=attachments
|
|
|
+ , values=values, choices=choices, results=results, 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'))
|
|
|
|
|
@@ -558,9 +647,17 @@ def vote(idvote):
|
|
|
def vote_deletechoices(idvote, iduser):
|
|
|
if int(iduser) != get_userid():
|
|
|
abort(401)
|
|
|
- g.db.execute('delete from user_choice where id_user = ? and id_choice in (select id from choices where id_vote = ?)',
|
|
|
- [iduser, idvote])
|
|
|
- g.db.commit()
|
|
|
+ vote = query_db('select votes.* from votes \
|
|
|
+ where votes.id=?', [idvote], one=True)
|
|
|
+ if not vote['is_terminated'] and not vote['is_anonymous']:
|
|
|
+ g.db.execute('delete from user_choice where id_user = ? and id_choice \
|
|
|
+ in (select id from choices where id_vote = ?)'
|
|
|
+ , [iduser, idvote])
|
|
|
+ g.db.commit()
|
|
|
+ g.db.execute('delete from user_vote where id_user = ? and id_vote \
|
|
|
+ in (select id_vote from choices where id_vote = ?)'
|
|
|
+ , [iduser, idvote])
|
|
|
+ g.db.commit()
|
|
|
return redirect(url_for('vote', idvote=idvote))
|
|
|
|
|
|
#-------------
|
|
@@ -579,6 +676,7 @@ def admin_votes():
|
|
|
def admin_vote_add():
|
|
|
if not session.get('user').get('is_admin'):
|
|
|
abort(401)
|
|
|
+ cardinals= OrderedDict([(len(values), {'name':name,'values':values,'first':first}) for (name, first, values) in CARDINALS])
|
|
|
if request.method == 'POST':
|
|
|
if request.form['title']:
|
|
|
if query_db('select * from votes where title = ?', [request.form['title']], one=True) is None:
|
|
@@ -586,29 +684,51 @@ def admin_vote_add():
|
|
|
date_end = date.today() + timedelta(days=int(request.form['days']))
|
|
|
transparent = 0
|
|
|
public = 0
|
|
|
- multiplechoice = 0
|
|
|
- if 'transparent' in request.form.keys():
|
|
|
+ anonymous = 0
|
|
|
+ if 'transparent' in request.form:
|
|
|
transparent = 1
|
|
|
- if 'public' in request.form.keys():
|
|
|
+ if 'public' in request.form:
|
|
|
public = 1
|
|
|
- if 'multiplechoice' in request.form.keys():
|
|
|
- multiplechoice = 1
|
|
|
+ if 'anonymous' in request.form:
|
|
|
+ anonymous = 1
|
|
|
+ try: quorum = float(request.form.get('quorum'))
|
|
|
+ except ValueError:
|
|
|
+ quorum = 0
|
|
|
+ if not (0 <= quorum and quorum <= 1):
|
|
|
+ flash(u'Une erreur est survenue !', 'error')
|
|
|
group = query_db('select id from groups where name = ?', [request.form['group']], one=True)
|
|
|
if group is None:
|
|
|
group[id] = 1
|
|
|
+ try: cardinal = int(request.form.get('cardinal'))
|
|
|
+ except ValueError:
|
|
|
+ cardinal = None
|
|
|
+ if cardinal in cardinals:
|
|
|
+ cardinal_name = cardinals[cardinal]['name']
|
|
|
+ cardinal_values = cardinals[cardinal]['values']
|
|
|
+ weight = cardinals[cardinal]['first'] if not cardinals[cardinal]['first'] is None else -(cardinal/2)
|
|
|
+ if query_db('select * from cardinals where id = ?', [cardinal], one=True) is None:
|
|
|
+ g.db.execute('insert into cardinals (id, name) values (?, ?)', [len(cardinal_values), cardinal_name])
|
|
|
+ g.db.commit()
|
|
|
+ for name in cardinal_values:
|
|
|
+ g.db.execute('insert into values_ (id_cardinal, name, weight) values (?, ?, ?)'
|
|
|
+ , [cardinal, name, weight])
|
|
|
+ g.db.commit()
|
|
|
+ weight += 1
|
|
|
g.db.execute('insert into votes (title, description, category, \
|
|
|
- date_begin, date_end, is_transparent, is_public, is_multiplechoice, id_group, id_author) \
|
|
|
- values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
|
|
+ date_begin, date_end, quorum, is_transparent, is_public, \
|
|
|
+ is_anonymous, id_group, id_author, id_cardinal) \
|
|
|
+ values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
|
|
[ request.form['title'], request.form['description'], request.form['category']
|
|
|
- , date_begin, date_end, transparent, public, multiplechoice, group['id'], session['user']['id'] ])
|
|
|
+ , date_begin, date_end, quorum, transparent, public, anonymous
|
|
|
+ , group['id'], session['user']['id'], cardinal ])
|
|
|
g.db.commit()
|
|
|
- vote = query_db('select * from votes where title = ? and date_begin = ? order by id desc',
|
|
|
- [request.form['title'], date_begin], one=True)
|
|
|
+ vote = query_db('select * from votes where title = ? and date_begin = ? order by id desc'
|
|
|
+ , [request.form['title'], date_begin], one=True)
|
|
|
if vote is None:
|
|
|
flash(u'Une erreur est survenue !', 'error')
|
|
|
return redirect(url_for('home'))
|
|
|
else:
|
|
|
- if request.form['pattern'] in PATTERNS.keys():
|
|
|
+ if request.form['pattern'] in PATTERNS:
|
|
|
pattern = PATTERNS[request.form['pattern']]
|
|
|
for choice in pattern:
|
|
|
g.db.execute('insert into choices (name, id_vote) values (?, ?)', [choice, vote['id']])
|
|
@@ -619,8 +739,9 @@ def admin_vote_add():
|
|
|
flash(u'Le titre que vous avez choisi est déjà pris.', 'error')
|
|
|
else:
|
|
|
flash(u'Vous devez spécifier un titre.', 'error')
|
|
|
- groups = query_db('select * from groups')
|
|
|
- return render_template('admin_vote_new.html', groups=groups, patterns=PATTERNS)
|
|
|
+ groups = query_db('select * from groups')
|
|
|
+ return render_template('admin_vote_new.html', groups=groups, cardinals=cardinals
|
|
|
+ , quorums=QUORUMS, patterns=PATTERNS)
|
|
|
|
|
|
@app.route('/admin/votes/edit/<voteid>', methods=['GET', 'POST'])
|
|
|
def admin_vote_edit(voteid):
|
|
@@ -636,15 +757,17 @@ def admin_vote_edit(voteid):
|
|
|
date_end = date_end.strftime("%Y-%m-%d")
|
|
|
transparent = 0
|
|
|
public = 0
|
|
|
- if 'transparent' in request.form.keys():
|
|
|
+ if 'transparent' in request.form:
|
|
|
transparent = 1
|
|
|
- if 'public' in request.form.keys():
|
|
|
+ if 'public' in request.form:
|
|
|
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:
|
|
|
+ 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'] >= 1:
|
|
|
isopen = 1
|
|
|
previousvote = query_db('select id, is_open, id_group from votes where id = ?', [voteid], one=True)
|
|
|
if previousvote is None or previousvote['is_open'] == 0:
|
|
@@ -672,15 +795,15 @@ def admin_vote_edit(voteid):
|
|
|
server.sendmail(EMAIL, [user['email']], BODY.encode('utf-8'))
|
|
|
server.quit()
|
|
|
else:
|
|
|
- flash(u'Vous devez proposer au moins deux choix pour ouvrir le vote.', 'error')
|
|
|
+ flash(u'Vous devez proposer au moins un choix pour ouvrir le vote.', 'error')
|
|
|
elif request.form['status'] == u'Terminé':
|
|
|
isterminated = 1
|
|
|
if vote['is_open']:
|
|
|
isopen = 1
|
|
|
- g.db.execute('update votes set title = ?, description = ?, category = ?, \
|
|
|
+ g.db.execute('update votes set title = ?, description = ?, category = ?, quorum = ?, \
|
|
|
is_transparent = ?, is_public = ?, is_open = ?, is_terminated = ?, \
|
|
|
date_end = ?, reminder_last_days = ? where id = ?',
|
|
|
- [ request.form['title'], request.form['description'], request.form['category']
|
|
|
+ [ request.form['title'], request.form['description'], request.form['category'], request.form['quorum']
|
|
|
, transparent, public, isopen, isterminated, date_end, request.form['reminder'], voteid ])
|
|
|
g.db.commit()
|
|
|
vote = query_db('select * from votes where id = ?', [voteid], one=True)
|
|
@@ -690,10 +813,11 @@ def admin_vote_edit(voteid):
|
|
|
vote['duration'] = (datetime.strptime(vote['date_end'], "%Y-%m-%d") - datetime.strptime(vote['date_begin'], "%Y-%m-%d")).days
|
|
|
group = query_db('select name from groups where id = ?', [vote['id_group']], one=True)
|
|
|
choices = query_db('select * from choices where id_vote = ?', [voteid])
|
|
|
+ values_ = query_db('select * from cardinals where id = ?', [vote['id_cardinal']], one=True)['name']
|
|
|
attachments = query_db('select * from attachments where id_vote = ?', [voteid])
|
|
|
if date.today().strftime("%Y-%m-%d") > vote['date_end']:
|
|
|
flash(u'La deadline du vote est expirée, vous devriez terminer le vote.')
|
|
|
- return render_template('admin_vote_edit.html', vote=vote, group=group, choices=choices, attachments=attachments)
|
|
|
+ return render_template('admin_vote_edit.html', vote=vote, group=group, values_=values_, choices=choices, attachments=attachments, quorums=QUORUMS)
|
|
|
|
|
|
@app.route('/admin/votes/delete/<idvote>')
|
|
|
def admin_vote_del(idvote):
|
|
@@ -738,7 +862,9 @@ def admin_vote_deletechoice(voteid, choiceid):
|
|
|
abort(404)
|
|
|
g.db.execute('delete from choices where id = ? and id_vote = ?', [choiceid, voteid])
|
|
|
g.db.commit()
|
|
|
- choices = query_db('select id_vote, count(*) as nb from choices where id_vote = ? group by id_vote', [voteid], one=True)
|
|
|
+ choices = query_db('select id_vote, count(*) as nb \
|
|
|
+ from choices where id_vote = ? \
|
|
|
+ group by id_vote', [voteid], one=True)
|
|
|
if choices is None or choices['nb'] < 2:
|
|
|
g.db.execute('update votes set is_open=0 where id = ?', [voteid])
|
|
|
g.db.commit()
|