abort(401)
if request.method == 'POST':
if request.form['title']:
- date_begin = date.today()
- date_end = date.today() + timedelta(days=int(request.form['days']))
- transparent = 0
- public = 0
- multiplechoice = 0
- if 'transparent' in request.form.keys():
- transparent = 1
- if 'public' in request.form.keys():
- public = 1
- if 'multiplechoice' in request.form.keys():
- multiplechoice = 1
- group = query_db('select id from groups where name = ?', [request.form['group']], one=True)
- if group is None:
- group[id] = 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
- [request.form['title'], request.form['description'], request.form['category'], date_begin, date_end, transparent, public, multiplechoice, group['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:120528: Bug possible car le titre n'est pas unique
- if vote is None:
- flash(u'Une erreur est survenue !', 'error')
- return redirect(url_for('home'))
+ if query_db('select * from votes where title = ?', [request.form['title']], one=True) is None:
+ date_begin = date.today()
+ date_end = date.today() + timedelta(days=int(request.form['days']))
+ transparent = 0
+ public = 0
+ multiplechoice = 0
+ if 'transparent' in request.form.keys():
+ transparent = 1
+ if 'public' in request.form.keys():
+ public = 1
+ if 'multiplechoice' in request.form.keys():
+ multiplechoice = 1
+ group = query_db('select id from groups where name = ?', [request.form['group']], one=True)
+ if group is None:
+ group[id] = 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
+ [request.form['title'], request.form['description'], request.form['category'], date_begin, date_end, transparent, public, multiplechoice, group['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)
+ if vote is None:
+ flash(u'Une erreur est survenue !', 'error')
+ return redirect(url_for('home'))
+ else:
+ flash(u"Le vote a été créé", 'info')
+ return redirect(url_for('admin_vote_edit', voteid=vote['id']))
else:
- flash(u"Le vote a été créé", 'info')
- return redirect(url_for('admin_vote_edit', voteid=vote['id']))
+ 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')
public = 1
isopen = 0
if request.form['status'] == 'Ouvert': # :TODO:maethor:120529: Check if there is at least 2 choices before
- isopen = 1
+ 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:
+ isopen = 1
+ else:
+ flash(u'Vous devez proposer au moins deux choix pour ouvrir le vote.', 'error')
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()
if request.method == 'POST':
g.db.execute('update choices set name=? where id = ? and id_vote = ?', [request.form['title'], choiceid, voteid])
g.db.commit()
- elif request.method == 'DELETE': # :COMMENT:maethor:120528: I can't find how to use it from template
- g.db.execute('delete from choices where id = ? and id_vote = ?', [choiceid, voteid])
- g.db.commt()
return redirect(url_for('admin_vote_edit', voteid=voteid))
@app.route('/admin/votes/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)
+ if choices is None or choices['nb'] < 2:
+ g.db.execute('update votes set is_open=0 where id = ?', [voteid])
+ g.db.commit()
+ flash(u'Attention ! Il y a moins de deux choix. Le vote a été fermé.', 'error')
return redirect(url_for('admin_vote_edit', voteid=voteid))
@app.route('/admin/votes/addattachment/<voteid>', methods=['POST'])