add deadlines
authorJulien Rabier <taziden@flexiden.org>
Tue, 22 May 2012 05:53:01 +0000 (07:53 +0200)
committerJulien Rabier <taziden@flexiden.org>
Tue, 22 May 2012 05:53:01 +0000 (07:53 +0200)
main.py
schema.sql
templates/show_votes.html

diff --git a/main.py b/main.py
index fdb1de4..036352a 100755 (executable)
--- 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'))
index 3a54680..836a026 100644 (file)
@@ -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
 );
 
index e6689db..e964efa 100644 (file)
@@ -16,7 +16,8 @@
   {% endif %}
   <ul class=votes>
   {% for vote in votes %}
-    <li><h2>{{ vote.title }}</h2>{{ vote.description|safe }}
+  <li><h2>{{ vote.title }} - {{ vote.description|safe }} </h2>
+  {{ vote.date }}
   {% else %}
     <li><em>Pas encore de votes</em>
   {% endfor %}