Fix issue with publisher
[cavote.git] / main.py
diff --git a/main.py b/main.py
index dc2259d..4ccd46c 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -381,7 +381,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.id as voteid, groups.name as groupname, users.name as author from (' + basequery + ') as votes join groups on groups.id = id_group join users on users.id = id_author 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'
     if votes == 'all':
         votes = query_db(basequery + ' order by date_end')
     elif votes == 'archive':
@@ -478,6 +478,11 @@ def vote(idvote):
                 vote['percent'] = int((float(vote['nb_votes']) / float(vote['max_votes'])) * 100)
         if query_db('select * from user_group where id_group = ? and id_user = ?', [vote['id_group'], get_userid()], one=True) and not vote['is_terminated']:
             flash(u'Ce vote vous concerne !', 'info')
+        publisher = query_db("select name from users where id = ?", [vote['id_author']], one=True)
+        if publisher is None:
+            vote['author'] = "NDN"
+        else:
+            vote['author'] = publisher['name']
         return render_template('vote.html', vote=vote, attachments=attachments, choices=choices, users=users.values(), can_vote=can_vote(idvote, get_userid()))
     flash(u'Vous n\'avez pas le droit de voir ce vote, désolé.')
     return redirect(url_for('home'))