- 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']))