|
@@ -125,7 +125,7 @@ def user_edit(userid):
|
|
|
g.db.execute('update users set email = ?, name = ?, organization = ? where id = ?',
|
|
|
[request.form['email'], request.form['name'], request.form['organization'], session['user']['id']])
|
|
|
g.db.commit()
|
|
|
- disconnect_user() # :TODO:maethor:120528: Maybe useless, but this is simple way to refresh session :D
|
|
|
+ disconnect_user()
|
|
|
user = query_db('select * from users where id=?', [userid], one=True)
|
|
|
if user is None:
|
|
|
flash(u'Une erreur s\'est produite.', 'error')
|
|
@@ -269,19 +269,47 @@ def can_see_vote(idvote, iduser=-1):
|
|
|
return True # :TODO:maethor:120529: Check others things
|
|
|
|
|
|
def can_vote(idvote, iduser=-1):
|
|
|
+ # :TODO:maethor:120604: Check if user has'nt already vote
|
|
|
if not can_see_vote(idvote, iduser):
|
|
|
return False
|
|
|
return True # :TODO:maethor:120529: Check others things
|
|
|
|
|
|
-@app.route('/vote/<idvote>')
|
|
|
+@app.route('/vote/<idvote>', methods=['GET', 'POST'])
|
|
|
def vote(idvote):
|
|
|
vote = query_db('select *, roles.name as rolename from votes join roles on roles.id=votes.id_role where votes.id=?', [idvote], one=True)
|
|
|
if vote is None:
|
|
|
abort(404)
|
|
|
if can_see_vote(idvote, session.get('user').get('id')):
|
|
|
- choices = query_db('select * from choices where id_vote=?', [idvote])
|
|
|
+ choices = query_db('select name, id from choices where id_vote=?', [idvote])
|
|
|
+ if request.method == 'POST':
|
|
|
+ if can_vote(idvote, session.get('user').get('id')):
|
|
|
+ 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()
|
|
|
+ if vote['is_multiplechoice'] == 0:
|
|
|
+ break
|
|
|
+ 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:
|
|
|
+ choice = dict()
|
|
|
+ choice['id'] = t['choiceid']
|
|
|
+ choice['name'] = t['choicename']
|
|
|
+ users[t['userid']]['choices'].append(choice)
|
|
|
+ else:
|
|
|
+ users[t['userid']] = dict()
|
|
|
+ users[t['userid']]['userid'] = t['userid']
|
|
|
+ users[t['userid']]['username'] = t['username']
|
|
|
+ choice = dict()
|
|
|
+ choice['id'] = t['choiceid']
|
|
|
+ choice['name'] = t['choicename']
|
|
|
+ users[t['userid']]['choices'] = [choice]
|
|
|
attachments = query_db('select * from attachments where id_vote=?', [idvote])
|
|
|
- return render_template('vote.html', vote=vote, attachments=attachments, choices=choices, can_vote=can_vote(idvote, session.get('user').get('id')))
|
|
|
+ return render_template('vote.html', vote=vote, attachments=attachments, choices=choices, users=users.values(), can_vote=can_vote(idvote, session.get('user').get('id')))
|
|
|
flash('Vous n\'avez pas le droit de voir ce vote, désolé.')
|
|
|
return(url_for('home'))
|
|
|
|