From: Julien Rabier Date: Tue, 22 May 2012 05:53:01 +0000 (+0200) Subject: add deadlines X-Git-Url: http://git.cyclocoop.org/?p=cavote.git;a=commitdiff_plain;h=39efd2236433e4a74704e536f2d52ead7d7e994d add deadlines --- diff --git a/main.py b/main.py index fdb1de4..036352a 100755 --- a/main.py +++ b/main.py @@ -4,7 +4,7 @@ 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=+:' @@ -28,16 +28,16 @@ def teardown_request(exception): @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')) diff --git a/schema.sql b/schema.sql index 3a54680..836a026 100644 --- a/schema.sql +++ b/schema.sql @@ -2,6 +2,7 @@ drop table if exists votes; create table votes ( id integer primary key autoincrement, title string not null, - description stringnot null + description string not null, + date datetime not null ); diff --git a/templates/show_votes.html b/templates/show_votes.html index e6689db..e964efa 100644 --- a/templates/show_votes.html +++ b/templates/show_votes.html @@ -16,7 +16,8 @@ {% endif %}