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/<idvote>')
+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
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])
--- /dev/null
+{% extends "layout.html" %}
+{% block body %}
+<h2>{{ vote.title }}</h2>
+<div class="row">
+<div class="span10 offset1">
+<table class="table table-condensed table-striped table-bordered">
+ <thead>
+ <tr>
+ <th></th>
+ {% for choice in choices %}
+ <th>{{ choice.name }}</th>
+ {% endfor %}
+ <th></th>
+ </tr>
+ </thead>
+
+ <tbody>
+ {% if vote.is_transparent %}
+ <!-- :TODO:maethor:20120528: Afficher les votes ici -->
+ {% else %}
+ <div class="alert alert-info">Ce sondage n'est pas transparent, vous ne pouvez pas voir les votes des autres.</div>
+ <!-- :TODO:maethor:20120528: Afficher le vote de l'utilisateur -->
+ {% endif %}
+
+ {% if can_vote %}
+ <form class="form-inline" action=""> <!-- :TODO:maethor:20120528: Route -->
+ <tr>
+ <td><input type='text' name="username" value='{{ session.user.name }}' disabled /></td>
+ {% if vote.is_multiple %}
+ {% for choice in choices %}
+ <td><input type='checkbox' name="{{ choice.id }}" /></td>
+ {% endfor %}
+ {% else %}
+ {% for choice in choices %}
+ <td><input type='radio' name="choice" value="{{ choice.id }}" /></td>
+ {% endfor %}
+ {% endif %}
+ <td><input type="submit" class="btn btn-primary" value="OK" /></td>
+ </tr>
+ </form>
+ {% endif %}
+ </tbody>
+ <tfoot>
+ {% if vote.is_transparent %}
+ <tr>
+ <td style="text-align: right">Somme</td>
+ {% for choice in choices %}
+ <td>nb</td>
+ {% endfor %}
+ <td></td>
+ </tr>
+ {% endif %}
+ </tfoot>
+</table>
+</div>
+</div>
+{% endblock %}
+