|
@@ -201,8 +201,11 @@ def add_vote():
|
|
|
public = 1
|
|
|
if 'multiplechoice' in request.form.keys():
|
|
|
multiplechoice = 1
|
|
|
- g.db.execute('insert into votes (title, description, date_begin, date_end, is_transparent, is_public, is_multiplechoice) values (?, ?, ?, ?, ?, ?, ?)',
|
|
|
- [request.form['title'], request.form['description'], date_begin, date_end, transparent, public, multiplechoice])
|
|
|
+ role = query_db('select id from roles where name = ?', [request.form['role']], one=True)
|
|
|
+ if role is None:
|
|
|
+ role[id] = 1
|
|
|
+ g.db.execute('insert into votes (title, description, category, date_begin, date_end, is_transparent, is_public, is_multiplechoice, id_role, id_author) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
|
|
+ [request.form['title'], request.form['description'], request.form['category'], date_begin, date_end, transparent, public, multiplechoice, role['id'], session['user']['id']])
|
|
|
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) # :DEBUG:maethor:20120528: Bug possible car le titre n'est pas unique
|
|
@@ -214,7 +217,8 @@ def add_vote():
|
|
|
return redirect(url_for('edit_vote', voteid=vote['id']))
|
|
|
else:
|
|
|
flash(u'Vous devez spécifier un titre.', 'error')
|
|
|
- return render_template('new_vote.html')
|
|
|
+ groups = query_db('select * from roles')
|
|
|
+ return render_template('new_vote.html', groups=groups)
|
|
|
|
|
|
@app.route('/votes/admin/edit/<voteid>', methods=['GET', 'POST'])
|
|
|
def edit_vote(voteid):
|
|
@@ -223,10 +227,31 @@ def edit_vote(voteid):
|
|
|
vote = query_db('select * from votes where id = ?', [voteid], one=True)
|
|
|
if vote is None:
|
|
|
abort(404)
|
|
|
- #if request.method == 'POST':
|
|
|
- # :TODO:maethor:20120528
|
|
|
+ if request.method == 'POST':
|
|
|
+ if request.form['title']:
|
|
|
+ # :TODO:maethor:120529: Calculer date_begin pour pouvoir y ajouter duration et obtenir date_end
|
|
|
+ transparent = 0
|
|
|
+ public = 0
|
|
|
+ if 'transparent' in request.form.keys():
|
|
|
+ transparent = 1
|
|
|
+ if 'public' in request.form.keys():
|
|
|
+ public = 1
|
|
|
+ isopen = 0
|
|
|
+ if request.form['status'] == 'Ouvert':
|
|
|
+ isopen = 1
|
|
|
+ g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ? where id = ?',
|
|
|
+ [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, voteid])
|
|
|
+ g.db.commit()
|
|
|
+ vote = query_db('select * from votes where id = ?', [voteid], one=True)
|
|
|
+ flash(u"Le vote a bien été mis à jour.", "success")
|
|
|
+ else:
|
|
|
+ flash(u'Vous devez spécifier un titre.', 'error')
|
|
|
+
|
|
|
+ # :TODO:maethor:20120529: Calculer la durée du vote (différence date_end - date_begin)
|
|
|
+ vote['duration'] = 15
|
|
|
+ group = query_db('select name from roles where id = ?', [vote['id_role']], one=True)
|
|
|
choices = query_db('select * from choices where id_vote = ?', [voteid])
|
|
|
- return render_template('edit_vote.html', vote=vote, choices=choices)
|
|
|
+ return render_template('edit_vote.html', vote=vote, group=group, choices=choices)
|
|
|
|
|
|
@app.route('/votes/admin/addchoice/<voteid>', methods=['POST'])
|
|
|
def add_choice(voteid):
|