From: Guillaume Subiron Date: Tue, 29 May 2012 11:41:05 +0000 (+0200) Subject: Show vote X-Git-Url: http://git.cyclocoop.org/?p=cavote.git;a=commitdiff_plain;h=e39a423e56697a035ea099e1f0ab4af1917a5d9e Show vote --- diff --git a/main.py b/main.py index 7ff598f..bff42a0 100755 --- a/main.py +++ b/main.py @@ -207,15 +207,41 @@ def del_role(idrole): def show_votes(votes): today = date.today() if votes == 'all': - votes = query_db('select title, description, date_begin, date_end from votes order by id desc') + votes = query_db('select * from votes order by id desc') elif votes == 'archive': - votes = query_db('select title, description, date_begin, date_end from votes where date_end < (?) order by id desc', [today]) + votes = query_db('select * from votes where date_end < (?) order by id desc', [today]) elif votes == 'current': - votes = query_db('select title, description, date_begin, date_end from votes where date_end >= (?) order by id desc', [today]) + votes = query_db('select * from votes where date_end >= (?) order by id desc', [today]) else: abort(404) return render_template('show_votes.html', votes=votes) +#------ +# Vote + +def can_see_vote(idvote, iduser=-1): + user = query_db('select * from users where id=?', [iduser], one=True) + vote = query_db('select * from votes where id=?', [idvote], one=True) + if user is None and not vote.is_public: + return False + return True # :TODO:maethor:20120529: Check others things + +def can_vote(idvote, iduser=-1): + if not can_see_vote(idvote, iduser): + return False + return True # :TODO:maethor:20120529: Check others things + +@app.route('/vote/') +def show_vote(idvote): + vote = query_db('select * from votes where id=?', [idvote], one=True) + if vote is None: + abort(404) + if can_see_vote(idvote, session.get('user').get('id')): + choices = query_db('select * from choices where id_vote=?', [idvote]) + return render_template('vote.html', vote=vote, choices=choices, can_vote=can_vote(idvote, session.get('user').get('id'))) + flash('Vous n\'avez pas le droit de voir ce vote, désolé.') + return(url_for('home')) + #------------- # Votes admin @@ -272,7 +298,7 @@ def edit_vote(voteid): if 'public' in request.form.keys(): public = 1 isopen = 0 - if request.form['status'] == 'Ouvert': + if request.form['status'] == 'Ouvert': # :TODO:maethor:20120529: Check if there is at least 2 choices before isopen = 1 g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ? where id = ?', [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, voteid]) diff --git a/templates/show_votes.html b/templates/show_votes.html index 079632b..5d7442e 100644 --- a/templates/show_votes.html +++ b/templates/show_votes.html @@ -4,7 +4,7 @@ {% for vote in votes %}
-

{{ vote.title }}

+

{{ vote.title }}


@@ -26,4 +26,3 @@
Il n'y a pas encore de votes. Désolé.
{% endfor %} {% endblock %} - diff --git a/templates/vote.html b/templates/vote.html new file mode 100644 index 0000000..b51896f --- /dev/null +++ b/templates/vote.html @@ -0,0 +1,58 @@ +{% extends "layout.html" %} +{% block body %} +

{{ vote.title }}

+
+
+ + + + + {% for choice in choices %} + + {% endfor %} + + + + + + {% if vote.is_transparent %} + + {% else %} +
Ce sondage n'est pas transparent, vous ne pouvez pas voir les votes des autres.
+ + {% endif %} + + {% if can_vote %} + + + + {% if vote.is_multiple %} + {% for choice in choices %} + + {% endfor %} + {% else %} + {% for choice in choices %} + + {% endfor %} + {% endif %} + + + + {% endif %} + + + {% if vote.is_transparent %} + + + {% for choice in choices %} + + {% endfor %} + + + {% endif %} + +
{{ choice.name }}
Sommenb
+
+
+{% endblock %} +