Commit 6742cbb2 by Őry Máté

dashboard: fix send_email_notifications implementation

parent 5d9f0a4a
......@@ -18,6 +18,8 @@
import logging
from django.conf import settings
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.template.loader import render_to_string
from django.utils import timezone
from django.utils.translation import ungettext, override
......@@ -31,20 +33,25 @@ logger = logging.getLogger(__name__)
def send_email_notifications():
msgs = {}
for i in Notification.objects.filter(,
q = Q( & (
Q( | Q(valid_until=None))
for i in Notification.objects.filter(q):
if not in msgs:
msgs[] = []
from_email = settings['DEFAULT_FROM_EMAIL']
from_email = settings.DEFAULT_FROM_EMAIL
for user, i in msgs.iteritems:
for user, i in msgs.iteritems():
if (not user.profile or not or not
logger.debug("%s gets no notifications", unicode(user))
with override(user.profile.language):
context = {'user': user, 'messages': i}
with override(user.profile.preferred_language):
context = {'user': user.profile, 'messages': i,
'url': (settings.DJANGO_URL.rstrip("/") +
'site': settings.COMPANY_NAME}
subject = ungettext("%d new notification",
"%d new notifications", len(i)) % len(i)
body = render_to_string('dashboard/notifications/email.txt',
......@@ -52,8 +59,10 @@ def send_email_notifications():
send_mail(subject, body, from_email, (, ))
logger.error("Failed to send mail to", user, exc_info=True)
logger.error("Failed to send mail to %s", user, exc_info=True)
else:"Delivered notifications %s",
" ".join( for j in i))
for j in i:
j.status = j.STATUS.delivered
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 sign in to comment