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 and is_hidden=0'
+ where is_hidden=0'
if votes == 'all':
- votes = query_db(basequery + ' order by date_end')
+ votes = query_db(basequery + ' and is_open=1 order by date_end')
elif votes == 'archive':
votes = query_db(basequery + ' and is_terminated=1 order by date_end desc')
elif votes == 'current':
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)
# 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 \
# 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:
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 = ?'
vote = query_db('select * from votes where id = ?', [voteid], one=True)
if vote is None:
abort(404)
+ print "\nvote: %s\n" % str(vote)
if request.method == 'POST':
if request.form['title']:
if request.form['days'] > 0:
choices = query_db('select * from choices where id_vote = ?', [voteid])
values_ = query_db('select * from cardinals where id = ?', [vote['id_cardinal']], one=True)['name']
attachments = query_db('select * from attachments where id_vote = ?', [voteid])
- if date.today().strftime("%Y-%m-%d") > vote['date_end']:
+ if date.today().strftime("%Y-%m-%d") > vote['date_end'] and not vote['is_terminated']:
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, values_=values_, choices=choices, attachments=attachments, quorums=QUORUMS)