From: Julien Moutinho Date: Sun, 19 Oct 2014 09:33:34 +0000 (+0200) Subject: add comments support X-Git-Url: http://git.cyclocoop.org/?p=cavote.git;a=commitdiff_plain;h=f2c5f4be15b6225e5e7d9f3c53084424beb32f1b add comments support --- diff --git a/main.py b/main.py index 14a839b..ccb7229 100755 --- a/main.py +++ b/main.py @@ -530,9 +530,10 @@ def vote(idvote): order by random()') g.db.execute('delete from user_choice_buffer_anonymous') g.db.commit() - g.db.execute('insert into user_vote (id_user, id_vote) \ - values (?, ?)' - , [session.get('user').get('id'), vote['id']]) + comment = request.form.get('comment', None) + g.db.execute('insert into user_vote (id_user, id_vote, comment) \ + values (?, ?, ?)' + , [session.get('user').get('id'), vote['id'], comment]) g.db.commit() else: abort(401) @@ -558,7 +559,7 @@ def vote(idvote): # ACTION: query users' choices joined with users' identity if not anonymous user_choices = query_db('select user_choice.id_user as userid, users.name as username, \ choices.id as choiceid, choices.name as choice_name, \ - user_choice.weight as weight \ + user_choice.weight as weight, user_vote.comment as comment \ from choices \ join user_choice on choices.id = user_choice.id_choice \ left join users on userid = users.id \ @@ -615,11 +616,12 @@ def vote(idvote): # ACTION: list user results per user users = OrderedDict() if vote['is_anonymous']: - user_votes = query_db('select users.name, id_user as userid \ + user_votes = query_db('select users.name, id_user as userid, comment \ from user_vote \ join users on users.id = id_user where id_vote = ?', [idvote]) for uc in user_votes: users[uc['userid']] = { 'username':uc['name'] + , 'comment':uc['comment'] , 'choices':{} , 'userid':uc['userid'] } else: @@ -633,6 +635,7 @@ def vote(idvote): else: users[uc['userid']] = { 'userid':uc['userid'] , 'username':uc['username'] + , 'comment':uc['comment'] , 'choices':{uc['choiceid']:value} } attachments = query_db('select * from attachments where id_vote=?', [idvote]) if query_db('select * from user_group where id_group = ? and id_user = ?' diff --git a/schema.sql b/schema.sql index 67475de..c2d5d25 100644 --- a/schema.sql +++ b/schema.sql @@ -122,6 +122,7 @@ create table user_vote ( date INTEGER DEFAULT CURRENT_TIMESTAMP NOT NULL, id_user INTEGER NOT NULL, id_vote INTEGER NOT NULL, + comment TEXT, FOREIGN KEY(id_user) REFERENCES users (id) ON DELETE CASCADE, FOREIGN KEY(id_vote) REFERENCES votes (id) ON DELETE CASCADE, PRIMARY KEY(id_user, id_vote) diff --git a/static/css/cavote.css b/static/css/cavote.css index 09cef79..397a8ef 100644 --- a/static/css/cavote.css +++ b/static/css/cavote.css @@ -3,16 +3,32 @@ margin-top:9px; } +.table-comments tbody tr td { + text-align:left; + } + .table-votes { - table-layout:fixed; + table-layout:fixed; } .table-votes thead th { text-align: right; vertical-align: middle; } +.table-votes thead th.users { + text-align:left; + padding-left:1em; + } .table-votes th.choice-name { text-align: center; } +.table-votes thead th.comments { + text-align:left; + padding-left:1em; + } +.table-votes tbody td.ok { + text-align:left; + padding-left:1em; + } .table-votes input { margin: 0; diff --git a/templates/vote.html b/templates/vote.html index d767473..5d1e4c6 100644 --- a/templates/vote.html +++ b/templates/vote.html @@ -120,12 +120,14 @@ - + {% for choice in choices %} {% endfor %} {% if 'user' in session and (can_vote or (not vote['is_terminated'] and not vote['is_anonymous'])) %} + {% else %} + {% endif %} {% if vote.is_transparent %} @@ -155,7 +157,8 @@ {% endfor %} - + {% endif %} @@ -171,7 +174,7 @@ {% endfor %} {% if 'user' in session and (can_vote or (not vote['is_terminated'] and not vote['is_anonymous'])) %} - + {% endif %} + {% if user.comment %}{{user.comment}}{%endif%} + + {% else %} + {% endif %} {% endif %} @@ -201,6 +210,18 @@ {% endif %} +{% if vote.is_anonymous %} +
+ +
Votant-e-s{{ choice.name }}Commentaires
+
{{ user.choices[choice.id].name }}{% if user.userid == session.user.id %} + {% if user.userid == session.user.id %} - {% endif %} + {% if user.comment %}{{user.comment}}{%endif%} +
+ + {% for user in users %} + + {% endfor %} + +
{% if user.comment %}{{user.comment}}{%endif%}
+{% endif %} + {% endblock %}