Commit e6bbbba6 authored by Arnaud Delcasse's avatar Arnaud Delcasse

Mail notifications during last days of a vote.

parent ed210a39
......@@ -57,7 +57,8 @@ Dans le répertoire de cavote, tappez :
- -D signifie que gunicorn sera lancé en daemon.
- Enlever vous permettrait de tester et pouvoir fermer le serveur en tappant Ctrl+C
- En mode daemon, un `pkill gunicorn` killera vos workers gunicorn
Pour activer les notifications par mail, mettez en place une tache cron appelant le script `reminder.py`.
Configurez nginx (`/etc/nginx/sites-enabled` ou `/etc/nginx/nginx.conf` ou
autre selon votre système)
......
......@@ -2,7 +2,8 @@ import os
import hashlib
import smtplib
import string
from datetime import time, date, timedelta
from datetime import date, datetime, timedelta
import time
from settings import *
......@@ -13,27 +14,29 @@ conn = sqlite3.connect(DATABASE)
c = conn.cursor()
for vote in c.execute('select id, id_group, date_end, title from votes where is_open=1 and is_terminated=0'):
print vote[0]
date_end_vote = date.fromtimestamp(vote[2])
date_today = date.today
date_end_vote = datetime.strptime(vote[2], "%Y-%m-%d")
date_today = datetime.today()
date_begin_reminder = date_end_vote + timedelta(days=-3)
if date_today >= date_begin_reminder and date_today <= date_end_vote:
voting_group = (vote[1],)
for user in c.executequery('select user.id, users.email, users.name from users join user_group on users.id=user_group.id_user where user_group.id_group = ?', voting_group):
userchoice_request = (user[0], vote[1],)
userchoice = c.executequery('select * from user_choice where id_user = ? and id_vote = ?', userchoice_request)
for user in c.execute('select users.id, users.email, users.name from users join user_group on users.id=user_group.id_user where user_group.id_group = ?', voting_group).fetchall():
userchoice_request = (user[0], vote[0],)
userchoice = c.execute('select * from user_choice join choices on user_choice.id_choice = choices.id where id_user = ? and id_vote = ?', userchoice_request).fetchone()
print "Checking if user %s already voted %s" % (user[1], vote[3])
print userchoice
if userchoice is None:
#user didn't vote yet
link = "http://vote.ffdn.org/vote/%d" % vote[0]
BODY = string.join((
"From: %s" % EMAIL,
"To: %s" % user[1],
"Subject: [Cavote] Vote reminder",
"Subject: [Cavote] Vote reminder - You didn't take part to it",
"Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()).decode('utf-8'),
"X-Mailer: %s" % VERSION,
"",
"A vote concerns you and is going to finish on %s : %s" % vote[2]%vote[3],
"A vote concerns you and is going to terminate on %s : %s" % (vote[2], vote[3]),
"You still didn't take part to it !",
"",
"This link will bring you to the form where you will be able to participate :",
link,
......@@ -41,5 +44,30 @@ for vote in c.execute('select id, id_group, date_end, title from votes where is_
"If you think this mail is not for you, please ignore and delete it."
), "\r\n")
server = smtplib.SMTP(SMTP_SERVER)
print EMAIL
print user[1]
print BODY
server.sendmail(EMAIL, user[1], BODY)
server.quit()
else:
BODY = string.join((
"From: %s" % EMAIL,
"To: %s" % user[1],
"Subject: [Cavote] Vote reminder - Last days to modify your choice",
"Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()).decode('utf-8'),
"X-Mailer: %s" % VERSION,
"",
"A vote concerns you and is going to terminate on %s : %s" % (vote[2], vote[3]),
"You have already voted by can still modify you choice",
"",
"This link will bring you to the form where you will be able to participate :",
link,
"",
"If you think this mail is not for you, please ignore and delete it."
), "\r\n")
server = smtplib.SMTP(SMTP_SERVER)
print EMAIL
print user[1]
print BODY
server.sendmail(EMAIL, user[1], BODY)
server.quit()
......@@ -7,6 +7,6 @@ SECRET_KEY = '{J@uRKO,xO-PK7B,jF?>iHbxLasF9s#zjOoy=+:'
DEBUG = True
TITLE = u"Cavote FFDN"
EMAIL = '"' + TITLE + '"' + ' <' + u"cavote@ffdn.org" + '>'
VERSION = "cavote 0.2.0"
VERSION = "cavote 0.3.0"
SMTP_SERVER = "127.0.0.1"
PATTERNS = {u'Oui/Non': [u'Oui', u'Non'], u'Oui/Non/Blanc': [u'Oui', u'Non', u'Blanc'], u'Oui/Non/Peut-être': [u'Oui', u'Non', u'Peut-être']}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment