aboutsummaryrefslogtreecommitdiffstats
path: root/famille.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2012-11-10 15:35:56 +0100
committerThibaut Horel <thibaut.horel@gmail.com>2012-11-10 15:35:56 +0100
commit305aa87825be13ba329fda96bd175b3dff0914bb (patch)
tree6744eac944ef42fe2043a0c8624f4ef8efb011f6 /famille.py
parentf96f407ebaf86fcf2cca1638527f1dc80d2b035c (diff)
downloadfamille-flask-305aa87825be13ba329fda96bd175b3dff0914bb.tar.gz
Add email notifications
Diffstat (limited to 'famille.py')
-rw-r--r--famille.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/famille.py b/famille.py
index ffc89fe..7ac36a7 100644
--- a/famille.py
+++ b/famille.py
@@ -9,6 +9,7 @@ from docutils import core
from docutils.writers.html4css1 import Writer
from datetime import datetime
from bs4 import BeautifulSoup
+from flask_mail import Mail, Message
def rstify(string):
w = Writer()
@@ -18,6 +19,7 @@ def rstify(string):
# configuration
app = Flask(__name__)
app.config.from_envvar('CONF')
+mail = Mail(app)
@app.template_filter('shortify')
def shortify(string):
@@ -90,6 +92,15 @@ def add_news():
if request.method == 'POST':
content = request.form['content']
content_cache = rstify(content)
+
+ # send email
+ emails = query_db("SELECT email from users where notify=1")
+ emails = [email["email"] for email in emails]
+ message = Message(request.form['title'], sender="news.horel@gmail.com")
+ message.html = content_cache
+ message.recipients = emails
+ mail.send(message)
+
cur = g.db.execute("INSERT INTO news "
"('title', 'content', 'user_id', 'content_cache') "
"VALUES (?, ?, ?, ?)",