Add vote deletion (only hides it in the DB : can be recovered manually from SQL by...
authorArnaud Delcasse <arnaud@delcasse.fr>
Mon, 3 Sep 2012 09:00:07 +0000 (11:00 +0200)
committerArnaud Delcasse <arnaud@delcasse.fr>
Mon, 3 Sep 2012 09:00:07 +0000 (11:00 +0200)
main.py
schema_0.1.X_to_0.2.X.sql [new file with mode: 0644]
templates/admin_votes.html

diff --git a/main.py b/main.py
index 4bbd46c..d56e251 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -21,7 +21,7 @@ SECRET_KEY = '{J@uRKO,xO-PK7B,jF?>iHbxLasF9s#zjOoy=+:'
 DEBUG = True
 TITLE = u"Cavote FFDN"
 EMAIL = '"' + TITLE + '"' + ' <' + u"cavote@ffdn.org" + '>'
 DEBUG = True
 TITLE = u"Cavote FFDN"
 EMAIL = '"' + TITLE + '"' + ' <' + u"cavote@ffdn.org" + '>'
-VERSION = "cavote 0.1.1"
+VERSION = "cavote 0.2.0"
 SMTP_SERVER = "127.0.0.1"
 PATTERNS = {u'Oui/Non': [u'Oui', u'Non'], u'Oui/Non/Blanc': [u'Oui', u'Non', u'Blanc'], u'Oui/Non/Peut-être': [u'Oui', u'Non', u'Peut-être']}
 
 SMTP_SERVER = "127.0.0.1"
 PATTERNS = {u'Oui/Non': [u'Oui', u'Non'], u'Oui/Non/Blanc': [u'Oui', u'Non', u'Blanc'], u'Oui/Non/Peut-être': [u'Oui', u'Non', u'Peut-être']}
 
@@ -418,7 +418,7 @@ def votes(votes):
     basequery = 'select votes.*, max_votes from votes left join (' + max_votes + ') as max_votes on votes.id_group = max_votes.id_group'
     nb_votes = 'select id_vote, count(*) as nb_votes from (select id_user, id_vote from user_choice join choices on id_choice = choices.id group by id_user, id_vote) group by id_vote'
     basequery = 'select * from (' + basequery + ') left join (' + nb_votes + ') on id = id_vote'
     basequery = 'select votes.*, max_votes from votes left join (' + max_votes + ') as max_votes on votes.id_group = max_votes.id_group'
     nb_votes = 'select id_vote, count(*) as nb_votes from (select id_user, id_vote from user_choice join choices on id_choice = choices.id group by id_user, id_vote) group by id_vote'
     basequery = 'select * from (' + basequery + ') left join (' + nb_votes + ') on id = id_vote'
-    basequery = 'select *, votes.id as voteid, groups.name as groupname from (' + basequery + ') as votes join groups on groups.id = id_group where is_open=1'
+    basequery = 'select *, votes.id as voteid, groups.name as groupname from (' + basequery + ') as votes join groups on groups.id = id_group where is_open=1 and is_hidden=0'
     if votes == 'all':
         votes = query_db(basequery + ' order by date_end')
     elif votes == 'archive':
     if votes == 'all':
         votes = query_db(basequery + ' order by date_end')
     elif votes == 'archive':
@@ -535,7 +535,7 @@ def vote_deletechoices(idvote, iduser):
 def admin_votes():
     if not session.get('user').get('is_admin'):
         abort(401)
 def admin_votes():
     if not session.get('user').get('is_admin'):
         abort(401)
-    votes = query_db('select *, votes.id as voteid, groups.name as groupname from votes join groups on groups.id=votes.id_group order by id desc')
+    votes = query_db('select *, votes.id as voteid, groups.name as groupname from votes join groups on groups.id=votes.id_group where is_hidden=0 order by id desc')
     return render_template('admin_votes.html', votes=votes, today=date.today().strftime("%Y-%m-%d"))
 
 @app.route('/admin/votes/add', methods=['GET', 'POST'])
     return render_template('admin_votes.html', votes=votes, today=date.today().strftime("%Y-%m-%d"))
 
 @app.route('/admin/votes/add', methods=['GET', 'POST'])
@@ -628,6 +628,17 @@ def admin_vote_edit(voteid):
         flash(u'La deadline du vote est expirée, vous devriez terminer le vote.')
     return render_template('admin_vote_edit.html', vote=vote, group=group, choices=choices, attachments=attachments)
 
         flash(u'La deadline du vote est expirée, vous devriez terminer le vote.')
     return render_template('admin_vote_edit.html', vote=vote, group=group, choices=choices, attachments=attachments)
 
+@app.route('/admin/votes/delete/<idvote>')
+def admin_vote_del(idvote):
+    if not session.get('user').get('is_admin'):
+        abort(401)
+    vote = query_db('select * from votes where id = ?', [idvote], one=True)
+    if vote is None:
+        abort(404)
+    g.db.execute('update votes set is_hidden=1 where id = ?', [idvote])
+    g.db.commit()
+    return redirect(url_for('admin_votes'))
+
 @app.route('/admin/votes/addchoice/<voteid>', methods=['POST'])
 def admin_vote_addchoice(voteid):
     if not session.get('user').get('is_admin'):
 @app.route('/admin/votes/addchoice/<voteid>', methods=['POST'])
 def admin_vote_addchoice(voteid):
     if not session.get('user').get('is_admin'):
diff --git a/schema_0.1.X_to_0.2.X.sql b/schema_0.1.X_to_0.2.X.sql
new file mode 100644 (file)
index 0000000..32cb736
--- /dev/null
@@ -0,0 +1,2 @@
+ALTER TABLE votes
+ADD is_hidden BOOLEAN DEFAULT 0 NOT NULL;
index b97e45a..40358ab 100644 (file)
       <td>
         <a href="{{ url_for('vote', idvote=vote.voteid) }}" class="btn btn-success btn-mini">Voir</a>
         <a href="{{ url_for('admin_vote_edit', voteid=vote.voteid) }}" class="btn btn-mini">Éditer</a>
       <td>
         <a href="{{ url_for('vote', idvote=vote.voteid) }}" class="btn btn-success btn-mini">Voir</a>
         <a href="{{ url_for('admin_vote_edit', voteid=vote.voteid) }}" class="btn btn-mini">Éditer</a>
+        <a href="#delete{{ vote.voteid }}" data-toggle="modal" class="btn btn-mini btn-danger">Supprimer</a>
       </td>
     </tr>
       </td>
     </tr>
+    <div class="modal hide fade" id="delete{{ vote.voteid }}">
+      <div class="modal-header">
+        <button type="button" class="close" data-dismiss="modal">×</button>
+        <h3>Suppression d'uun vote</h3>
+      </div>
+      <div class="modal-body">
+        <p>Voulez-vous vraiment supprimer le vote <strong>{{ vote.title }}</strong> ?</p>
+      </div>
+      <div class="modal-footer">
+        <a href="{{ url_for('admin_vote_del', idvote=vote.voteid) }}" class="btn btn-danger">Confirmer</a>
+        <a href="#" class="btn" data-dismiss="modal">Annuler</a>
+      </div>
+    </div>
     {% endfor %}
     </tbody>
   </table>
     {% endfor %}
     </tbody>
   </table>