|
@@ -144,6 +144,26 @@ def user_password(userid):
|
|
|
#------------
|
|
|
# User admin
|
|
|
|
|
|
+@app.route('/users/admin/add', methods=['GET', 'POST'])
|
|
|
+def add_user():
|
|
|
+ if not session.get('is_admin'):
|
|
|
+ abort(401)
|
|
|
+ if request.method == 'POST':
|
|
|
+ if request.form['email']:
|
|
|
+ # :TODO:maethor:120528: Check fields
|
|
|
+ password = "toto" # :TODO:maethor:120528: Generate password
|
|
|
+ admin = 0
|
|
|
+ if 'admin' in request.form.keys():
|
|
|
+ admin = 1
|
|
|
+ g.db.execute('insert into users (email, name, organization, password, is_admin) values (?, ?, ?, ?, ?)',
|
|
|
+ [request.form['email'], request.form['username'], request.form['organization'], password, admin])
|
|
|
+ g.db.commit()
|
|
|
+ # :TODO:maethor:120528: Send mail
|
|
|
+ flash(u'Le nouvel utilisateur a été créé avec succès', 'success')
|
|
|
+ return redirect(url_for('home'))
|
|
|
+ else:
|
|
|
+ flash(u"Vous devez spécifier une adresse email.", 'error')
|
|
|
+ return render_template('add_user.html')
|
|
|
|
|
|
#------------
|
|
|
# Votes list
|
|
@@ -164,32 +184,31 @@ def show_votes(votes):
|
|
|
#-------------
|
|
|
# Votes admin
|
|
|
|
|
|
-@app.route('/votes/admin/new')
|
|
|
-def new_vote():
|
|
|
- if not session.get('is_admin'):
|
|
|
- abort(401)
|
|
|
- return render_template('new_vote.html')
|
|
|
-
|
|
|
-@app.route('/votes/admin/add', methods=['POST'])
|
|
|
+@app.route('/votes/admin/add', methods=['GET', 'POST'])
|
|
|
def add_vote():
|
|
|
if not session.get('is_admin'):
|
|
|
abort(401)
|
|
|
- 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
|
|
|
- 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])
|
|
|
- g.db.commit()
|
|
|
- flash('New entry was successfully posted', 'info')
|
|
|
- return redirect(url_for('home'))
|
|
|
+ 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
|
|
|
+ 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])
|
|
|
+ g.db.commit()
|
|
|
+ flash('New entry was successfully posted', 'info')
|
|
|
+ return redirect(url_for('home'))
|
|
|
+ else:
|
|
|
+ flash(u'Vous devez spécifier un titre.', 'error')
|
|
|
+ return render_template('new_vote.html')
|
|
|
|
|
|
#------
|
|
|
# Main
|