from flask import Flask, request, session, g, redirect, url_for, abort, \
render_template, flash
import sqlite3
-from datetime import date
+from datetime import date, timedelta
DATABASE = '/tmp/cavote.db'
SECRET_KEY = '{J@uRKO,xO-PK7B,jF?>iHbxLasF9s#zjOoy=+:'
@app.route('/admin/votes')
def show_votes():
- cur = g.db.execute('select title, description from votes order by id desc')
- votes = [dict(title=row[0], description=row[1]) for row in cur.fetchall()]
+ 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()]
return render_template('show_votes.html', votes=votes)
@app.route('/admin/vote/add', methods=['POST'])
def add_vote():
if not session.get('logged_in'):
abort(401)
- g.db.execute('insert into votes (title, description) values (?, ?)',
- [request.form['title'], request.form['description']])
+ g.db.execute('insert into votes (title, description, date) values (?, ?, ?)',
+ [request.form['title'], request.form['description'], date.today() + timedelta(days=60)])
g.db.commit()
flash('New entry was successfully posted')
return redirect(url_for('show_votes'))