From 1d4364eb332f70a0f05ed411fc1c397c2e7ac4be Mon Sep 17 00:00:00 2001 From: Julien Moutinho Date: Sun, 19 Oct 2014 11:47:44 +0200 Subject: [PATCH] modify mail notification to make it optional --- main.py | 32 +++++++++++++++++++------------- templates/admin_vote_edit.html | 6 ++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index fde382f..a4c2e3f 100755 --- a/main.py +++ b/main.py @@ -771,33 +771,39 @@ def admin_vote_edit(voteid): public = 1 isopen = 0 isterminated = 0 + print "POST" if request.form['status'] == 'Ouvert': - choices = query_db('select id_vote, count(*) as nb \ - from choices where id_vote = ? \ + choices = query_db('select id_vote, count(*) as nb, groups.name as group_name \ + from choices \ + join votes on votes.id = choices.id_vote \ + join groups on groups.id = votes.id_group \ + where id_vote = ? \ group by id_vote', [voteid], one=True) if choices is not None and choices['nb'] >= 1: 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: + if (previousvote is None or previousvote['is_open'] == 0) and 'mail_notice' in request.form: 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] %s" % gettext(u"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'), - "Content-type: text/plain; charset=utf-8", - "X-Mailer: %s" % VERSION, + u"From: %s" % EMAIL, + u"To: %s" % user['email'], + u"Subject: [vote] [%s] %s" % (choices['group_name'], request.form['title']), + u"Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()).decode('utf-8'), + u"Content-type: text/plain; charset=utf-8", + u"X-Mailer: %s" % VERSION, "", - "%(text)s %(title)s" % {"text": gettext(u"A vote has been opened and you are in a group concerned by it :"), "title": request.form['title']}, - "", - gettext(u"This link will bring you to the form where you will be able to vote :"), + u"%(text0)s%(group)s" % \ + { "text0":gettext(u"A new vote concerns you within the group: ") \ + , "group":choices['group_name'] }, \ link, "", - gettext(u"If you think this mail is not for you, please ignore and delete it.") + gettext(u"If you think this mail is not for you, please ignore and delete it."), + gettext(u"For more informations, you can contact:"), + EMAIL ), "\r\n") server = smtplib.SMTP(SMTP_SERVER) server.sendmail(EMAIL, [user['email']], BODY.encode('utf-8')) diff --git a/templates/admin_vote_edit.html b/templates/admin_vote_edit.html index 5a467f3..4a45935 100644 --- a/templates/admin_vote_edit.html +++ b/templates/admin_vote_edit.html @@ -144,6 +144,12 @@ {% endif %} {% endif %} + {% if vote.is_open == 0 %} + + {% endif %}
-- 2.20.1