From ade6cbf708741d765b9303e6a36968b85a71baa0 Mon Sep 17 00:00:00 2001 From: Guillaume Subiron Date: Fri, 25 May 2012 20:07:18 +0200 Subject: [PATCH] =?utf8?q?Ajout=20d'une=20barre=20de=20menu,=20r=C3=A9?= =?utf8?q?=C3=A9criture=20des=20formulaires,=20ajout=20d'attribut=20dans?= =?utf8?q?=20la=20table=20votes?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- main.py | 28 +++++++++++--- schema.sql | 20 ++++++++-- templates/layout.html | 41 ++++++++------------- templates/login.html | 27 ++++++++------ templates/new_vote.html | 77 +++++++++++++++++++++++++++++++++++++++ templates/show_votes.html | 33 ++++------------- 6 files changed, 155 insertions(+), 71 deletions(-) create mode 100644 templates/new_vote.html diff --git a/main.py b/main.py index 57c876b..a8bc229 100755 --- a/main.py +++ b/main.py @@ -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) diff --git a/schema.sql b/schema.sql index d138caa..4b23934 100644 --- a/schema.sql +++ b/schema.sql @@ -1,8 +1,20 @@ drop table if exists votes; create table votes ( - id integer primary key autoincrement, - title string not null, - description string not null, - date string not null + id INTEGER primary key autoincrement, + title TEXT not null, + description TEXT, + category TEXT, + date_begin INTEGER default CURRENT_TIMESTAMP not null, + date_end INTEGER not null, + is_transparent INTEGER default 1 not null, + is_public INTEGER default 1 not null, + is_multiplechoice INTEGER default 1 not null, + is_weighted INTEGER default 0 not null, + is_closed INTEGER default 0 not null + --id_author INTEGER not null, + --id_role INTEGER, + --FOREIGN KEY(id_author) REFERENCES user(id), + --FOREIGN KEY(id_role) REFERENCES role(id) ); + diff --git a/templates/layout.html b/templates/layout.html index 0ac3eb6..0234d90 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -13,37 +13,25 @@ -
+
+
+ Accueil + Votes en cours + Archives + {% if session.is_admin %} + Admin + + {% endif %} +
{% if not session.logged_in %} - Connexion + Connexion {% else %} {{ session.nickname }} @@ -56,8 +44,9 @@ {% endif %}
+
-

Outil de vote du CA FFDN

+

Outil de vote du CA FFDN

{% with messages = get_flashed_messages() %} {% if messages %} {% for message in messages %} diff --git a/templates/login.html b/templates/login.html index 6f70bb7..334caa1 100644 --- a/templates/login.html +++ b/templates/login.html @@ -1,14 +1,19 @@ {% extends "layout.html" %} {% block body %} -

Login

- {% if error %}

Error: {{ error }}{% endif %} -

-
-
Username: -
-
Password: -
-
-
-
+
+
+ {% if error %}
Error: {{ error }}
{% endif %} +
+
Connexion + + + + +
+ +
+
+

Mot de passe perdu ?

+
+
{% endblock %} diff --git a/templates/new_vote.html b/templates/new_vote.html new file mode 100644 index 0000000..ecd7ba2 --- /dev/null +++ b/templates/new_vote.html @@ -0,0 +1,77 @@ +{% extends "layout.html" %} +{% block body %} + +
+
+
+
Ajouter un vote +
+ +
+ + * +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +

Groupe d'utilisateur concernés par le vote et ayant le droit de voter

+
+
+
+ +
+ +
+
+
+ +
+ + + +
+
+
+ +
+
+
+
+
+ +{% endblock %} diff --git a/templates/show_votes.html b/templates/show_votes.html index 9aec632..079632b 100644 --- a/templates/show_votes.html +++ b/templates/show_votes.html @@ -1,21 +1,18 @@ {% extends "layout.html" %} {% block body %} - -
-

Liste des votes

- - {% if session.logged_in %} -

Ajouter un vote

-
-
-
Question soumise au vote : -
-
Description (facultative) : -
-
-
-
- {% endif %} - Retour à l'accueil - {% endblock %} -- 2.20.1