X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=main.py;h=4832fd3eddda2064045d5d721fdb8a72c453face;hb=55ac14c2220d373540fc715ba6db393ab80475ae;hp=3ac3664959a7752828f3a200e8e208516922644d;hpb=0f93afde08f333a6615145615f424db26240b512;p=cavote.git diff --git a/main.py b/main.py index 3ac3664..4832fd3 100755 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ from flask import Flask, request, session, g, redirect, url_for, abort, \ render_template, flash -from flaskext.openid import OpenID +from flask_openid import OpenID import sqlite3 from datetime import date, time, timedelta, datetime import time @@ -17,7 +17,8 @@ import string from settings import * -app = Flask(__name__) app.config.from_object(__name__) +app = Flask(__name__) +app.config.from_object(__name__) oid = OpenID(app) @@ -181,7 +182,7 @@ def login_key(userid, key): def user(userid): if int(userid) != get_userid(): abort(401) - groups = query_db('select * from groups join user_group on id=id_group where id_user = ?', userid) + groups = query_db('select * from groups join user_group on id=id_group where id_user = ?', (userid,)) return render_template('user.html', groups=groups) @app.route('/user/settings/', methods=['GET', 'POST']) @@ -597,14 +598,36 @@ def admin_vote_edit(voteid): choices = query_db('select id_vote, count(*) as nb from choices where id_vote = ? group by id_vote', [voteid], one=True) if choices is not None and choices['nb'] >= 2: isopen = 1 + previousvote = query_db('select id, is_open, id_group from votes where id = ?', [voteid], one=True) + if previousvote is None or previousvote['is_open'] == 0: + users_to_vote = query_db('select users.email, users.name from users join user_group on users.id=user_group.id_user where user_group.id_group = ?', [previousvote['id_group']]) + for user in users_to_vote: + link = request.url_root + url_for('vote', idvote=voteid) + BODY = string.join(( + "From: %s" % EMAIL, + "To: %s" % user['email'], + "Subject: [Cavote] A vote has been opened for your group", + "Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()).decode('utf-8'), + "X-Mailer: %s" % VERSION, + "", + "A vote has been opened and you are in a group concerned by it : %s" % request.form['title'], + "", + "This link will bring you to the form where you will be able to vote :", + link, + "", + "If you think this mail is not for you, please ignore and delete it." + ), "\r\n") + server = smtplib.SMTP(SMTP_SERVER) + server.sendmail(EMAIL, [user['email']], BODY) + server.quit() else: flash(u'Vous devez proposer au moins deux choix pour ouvrir le vote.', 'error') elif request.form['status'] == u'Terminé': isterminated = 1 if vote['is_open']: isopen = 1 - g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ?, is_terminated = ?, date_end = ? where id = ?', - [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, isterminated, date_end, voteid]) + g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ?, is_terminated = ?, date_end = ?, reminder_last_days = ? where id = ?', + [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, isterminated, date_end, request.form['reminder'], voteid]) g.db.commit() vote = query_db('select * from votes where id = ?', [voteid], one=True) flash(u"Le vote a bien été mis à jour.", "success")