From ceddf4b06d5bc343c8de8016ead00ab99abdfeac Mon Sep 17 00:00:00 2001 From: Guillaume Subiron Date: Mon, 4 Jun 2012 10:14:57 +0200 Subject: [PATCH] Attachments --- main.py | 25 ++++++++++++++++++++++++- schema.sql | 4 ++-- templates/admin_vote_edit.html | 30 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index a8f91a6..a807a51 100755 --- a/main.py +++ b/main.py @@ -362,7 +362,8 @@ def admin_vote_edit(voteid): vote['duration'] = 15 group = query_db('select name from roles where id = ?', [vote['id_role']], one=True) choices = query_db('select * from choices where id_vote = ?', [voteid]) - return render_template('admin_vote_edit.html', vote=vote, group=group, choices=choices) + attachments = query_db('select * from attachments where id_vote = ?', [voteid]) + return render_template('admin_vote_edit.html', vote=vote, group=group, choices=choices, attachments=attachments) @app.route('/admin/votes/addchoice/', methods=['POST']) def admin_vote_addchoice(voteid): @@ -401,6 +402,28 @@ def admin_vote_deletechoice(voteid, choiceid): g.db.commit() return redirect(url_for('admin_vote_edit', voteid=voteid)) +@app.route('/admin/votes/addattachment/', methods=['POST']) +def admin_vote_addattachment(voteid): + if not session.get('user').get('is_admin'): + abort(401) + vote = query_db('select * from votes where id = ?', [voteid], one=True) + if vote is None: + abort(404) + g.db.execute('insert into attachments (url, id_vote) values (?, ?)', [request.form['url'], voteid]) + g.db.commit() + return redirect(url_for('admin_vote_edit', voteid=voteid)) + +@app.route('/admin/votes/deleteattachment//') +def admin_vote_deleteattachment(voteid, attachmentid): + if not session.get('user').get('is_admin'): + abort(401) + attachment = query_db('select * from attachments where id = ? and id_vote = ?', [attachmentid, voteid], one=True) + if attachment is None: + abort(404) + g.db.execute('delete from attachments where id = ? and id_vote = ?', [attachmentid, voteid]) + g.db.commit() + return redirect(url_for('admin_vote_edit', voteid=voteid)) + #------ # Main diff --git a/schema.sql b/schema.sql index f03e176..20ddccb 100644 --- a/schema.sql +++ b/schema.sql @@ -48,10 +48,10 @@ create table votes ( ); create table attachments ( + id INTEGER primary key autoincrement, url TEXT not null, id_vote INTEGER not null, - FOREIGN KEY(id_vote) REFERENCES vote(id), - PRIMARY KEY(url, id_vote) + FOREIGN KEY(id_vote) REFERENCES vote(id) ); create table choices ( diff --git a/templates/admin_vote_edit.html b/templates/admin_vote_edit.html index 841e15b..321ae85 100644 --- a/templates/admin_vote_edit.html +++ b/templates/admin_vote_edit.html @@ -138,6 +138,36 @@ + +
+
Pièces jointes + + + + + + + {% for attachment in attachments %} + + + + + {% endfor %} + + + + + + + +
Lien + Actions +
{{ attachment.url }}Supprimer
+ +
+
+
+ {% endblock %} -- 2.20.1