Browse Source

add deadlines

Julien Rabier 13 years ago
parent
commit
39efd22364
3 changed files with 9 additions and 7 deletions
  1. 5 5
      main.py
  2. 2 1
      schema.sql
  3. 2 1
      templates/show_votes.html

+ 5 - 5
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'))

+ 2 - 1
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
 );
 

+ 2 - 1
templates/show_votes.html

@@ -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 %}