|
@@ -34,18 +34,34 @@ def home():
|
|
|
|
|
|
@app.route('/admin/votes')
|
|
|
def show_votes():
|
|
|
- cur = g.db.execute('select title, description, date from votes order by id desc')
|
|
|
- votes = [dict(title=row[0], description=row[1], date=row[2]) for row in cur.fetchall()]
|
|
|
+ cur = g.db.execute('select title, description, date_begin, date_end from votes order by id desc')
|
|
|
+ votes = [dict(title=row[0], description=row[1], date_begin=row[2], date_end=row[3],
|
|
|
+ pourcent=60) for row in cur.fetchall()]
|
|
|
return render_template('show_votes.html', votes=votes)
|
|
|
|
|
|
+@app.route('/admin/votes/new')
|
|
|
+def new_vote():
|
|
|
+ if not session.get('logged_in'):
|
|
|
+ abort(401)
|
|
|
+ return render_template('new_vote.html')
|
|
|
+
|
|
|
@app.route('/admin/vote/add', methods=['POST'])
|
|
|
def add_vote():
|
|
|
if not session.get('logged_in'):
|
|
|
abort(401)
|
|
|
- daten = date.today() + timedelta(days=60)
|
|
|
+ daten = date.today() + timedelta(days=int(request.form['days']))
|
|
|
ndate = daten.strftime('%d %B %Y')
|
|
|
- g.db.execute('insert into votes (title, description, date) values (?, ?, ?)',
|
|
|
- [request.form['title'], request.form['description'], ndate])
|
|
|
+ transparent = 0
|
|
|
+ public = 0
|
|
|
+ multiplechoice = 0
|
|
|
+ if request.form['transparent'] == "on":
|
|
|
+ transparent = 1
|
|
|
+ if request.form['public'] == "on":
|
|
|
+ public = 1
|
|
|
+ if request.form['multiplechoice'] == "on":
|
|
|
+ multiplechoice = 1
|
|
|
+ g.db.execute('insert into votes (title, description, date_end, is_transparent, is_public, is_multiplechoice) values (?, ?, ?, ?, ?, ?)',
|
|
|
+ [request.form['title'], request.form['description'], ndate, transparent, public, multiplechoice])
|
|
|
g.db.commit()
|
|
|
flash('New entry was successfully posted')
|
|
|
return redirect(url_for('home'))
|
|
@@ -61,6 +77,8 @@ def login():
|
|
|
else:
|
|
|
session['logged_in'] = True
|
|
|
session['nickname'] = request.form['username']
|
|
|
+ if session['nickname'] == 'admin':
|
|
|
+ session['is_admin'] = True
|
|
|
flash('You were logged in')
|
|
|
return redirect(url_for('home'))
|
|
|
return render_template('login.html', error=error)
|