From: Guillaume Subiron Date: Mon, 28 May 2012 20:09:37 +0000 (+0200) Subject: Edit vote X-Git-Url: http://git.cyclocoop.org/%27http:/code.google.com/p/ie7-js/%27%40url%40/%40%20%27info_date_publication_anterieure%27%20=%3E%20%27Previously%20published%20on:%27%2C%20%27info_date_referencement%27%20=%3E%20%27THIS%20SITE%20REFERENCED%20ON:%27%2C%20%27info_derniere_etape%27%20=%3E%20%27Done%21%27%2C-%27info_derniers_articles_publies%27%20=%3E%20%27Your%20most%20recently%20published%20articles%27%2C-%27info_desactiver_messagerie_personnelle%27%20=%3E%20%27You%20can%20enable%20or%20disable%20your%20personal%20messaging%20on%20this%20site.%27%2C%20%27info_descriptif%27%20=%3E%20%27Description:%27%2C%20%27info_desinstaller_plugin%27%20=%3E%20%27%20deactivates%20the%20plugin%20and%20deletes%20the%20data%27%2C%20%27info_discussion_cours%27%20=%3E%20%27Current%20discussions%27%2C%40%40%20-332%2C7%20%20284%2C6%20%40%40%20Do%20not%20submit%20this%20import%20request.%3Cp%3EFor%20more%20information%2C%20please%20see%20%3Ca%20href=?a=commitdiff_plain;h=f42b7613c22add2650031ac5fa04065d82393436;p=cavote.git Edit vote --- diff --git a/main.py b/main.py index 4662b59..c26c2cb 100755 --- a/main.py +++ b/main.py @@ -204,12 +204,67 @@ def add_vote(): g.db.execute('insert into votes (title, description, date_begin, date_end, is_transparent, is_public, is_multiplechoice) values (?, ?, ?, ?, ?, ?, ?)', [request.form['title'], request.form['description'], date_begin, date_end, transparent, public, multiplechoice]) g.db.commit() - flash('New entry was successfully posted', 'info') - return redirect(url_for('home')) + vote = query_db('select * from votes where title = ? and date_begin = ? order by id desc', + [request.form['title'], date_begin], one=True) # :DEBUG:maethor:20120528: Bug possible car le titre n'est pas unique + if vote is None: + flash(u'Une erreur est survenue !', 'error') + return redirect(url_for('home')) + else: + flash(u"Le vote a été créé", 'info') + return redirect(url_for('edit_vote', voteid=vote['id'])) else: flash(u'Vous devez spécifier un titre.', 'error') return render_template('new_vote.html') +@app.route('/votes/admin/edit/', methods=['GET', 'POST']) +def edit_vote(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) + #if request.method == 'POST': + # :TODO:maethor:20120528 + choices = query_db('select * from choices where id_vote = ?', [voteid]) + return render_template('edit_vote.html', vote=vote, choices=choices) + +@app.route('/votes/admin/addchoice/', methods=['POST']) +def add_choice(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 choices (name, id_vote) values (?, ?)', [request.form['title'], voteid]) + g.db.commit() + return redirect(url_for('edit_vote', voteid=voteid)) + +@app.route('/votes/admin/editchoice//', methods=['POST', 'DELETE']) +def edit_choice(voteid, choiceid): + if not session.get('user').get('is_admin'): + abort(401) + choice = query_db('select * from choices where id = ? and id_vote = ?', [choiceid, voteid], one=True) + if choice is None: + abort(404) + if request.method == 'POST': + g.db.execute('update choices set name=? where id = ? and id_vote = ?', [request.form['title'], choiceid, voteid]) + g.db.commit() + elif request.method == 'DELETE': # :COMMENT:maethor:20120528: I can't find how to use it from template + g.db.execute('delete from choices where id = ? and id_vote = ?', [choiceid, voteid]) + g.db.commt() + return redirect(url_for('edit_vote', voteid=voteid)) + +@app.route('/votes/admin/deletechoice//') +def delete_choice(voteid, choiceid): + if not session.get('user').get('is_admin'): + abort(401) + choice = query_db('select * from choices where id = ? and id_vote = ?', [choiceid, voteid], one=True) + if choice is None: + abort(404) + g.db.execute('delete from choices where id = ? and id_vote = ?', [choiceid, voteid]) + g.db.commit() + return redirect(url_for('edit_vote', voteid=voteid)) + #------ # Main diff --git a/schema.sql b/schema.sql index b7fa00b..5529a31 100644 --- a/schema.sql +++ b/schema.sql @@ -1,3 +1,4 @@ +drop table if exists choices; drop table if exists votes; drop table if exists users; @@ -22,13 +23,20 @@ create table votes ( 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, + is_open INTEGER default 0 not null, id_author INTEGER, -- :COMMENT:maethor:120528: not null ? --id_role INTEGER, FOREIGN KEY(id_author) REFERENCES users(id) --FOREIGN KEY(id_role) REFERENCES role(id) ); +create table choices ( + id INTEGER primary key autoincrement, + name TEXT not null, + id_vote INTEGER not null, + FOREIGN KEY(id_vote) REFERENCES vote(id) +); + -- Test data insert into users (email, password, name, organization, is_admin, key) values ("admin@admin.fr", "admin", "Toto (admin) Tata", "World corp", 1, "test"); diff --git a/templates/edit_vote.html b/templates/edit_vote.html new file mode 100644 index 0000000..4319631 --- /dev/null +++ b/templates/edit_vote.html @@ -0,0 +1,146 @@ +{% extends "layout.html" %} +{% block body %} + +
+
+
+
Édition du vote +
+ +
+ + * +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +

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

+
+
+
+
+
+
+
+ + Options +
+
+
+
+ +
+ +
+
+
+ +
+ + + {% if not vote.is_open %} + + {% endif %} +
+
+
+
+
+
+
+ +
+ +
+
+
+ + +
+
+
+
+ +
+
Choix + + + + + + + {% for choice in choices %} + + + + + + + {% endfor %} + + + + + + + +
Titre + Actions +
+ Supprimer
+ +
+
+
+
+ +{% endblock %} diff --git a/templates/new_vote.html b/templates/new_vote.html index 575e9f6..0adca60 100644 --- a/templates/new_vote.html +++ b/templates/new_vote.html @@ -67,7 +67,7 @@
- +