Commit e0199de6 by Őry Máté

dashboard: send collected notifications in mail

parent e4141022
......@@ -1092,7 +1092,7 @@ class TraitForm(forms.ModelForm):
class MyProfileForm(forms.ModelForm):
class Meta:
fields = ('preferred_language', )
fields = ('preferred_language', 'email_notifications', )
model = Profile
......@@ -84,6 +84,9 @@ class Profile(Model):
help_text=_('Unique identifier of the person, e.g. a student number.'))
instance_limit = IntegerField(default=5)
use_gravatar = BooleanField(default=False)
email_notifications = BooleanField(
verbose_name=_("Email notifications"), default=True,
help_text=_('Wether user wants to get digested email notifications.'))
def notify(self, subject, template, context={}, valid_until=None):
return Notification.send(self.user, subject, template, context,
# Copyright 2014 Budapest University of Technology and Economics (BME IK)
# This file is part of CIRCLE Cloud.
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <>.
import logging
from django.conf import settings
from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.utils import timezone
from django.utils.translation import ungettext, override
from manager.mancelery import celery
from ..models import Notification
logger = logging.getLogger(__name__)
def send_email_notifications():
msgs = {}
for i in Notification.objects.filter(,
if not in msgs:
msgs[] = []
from_email = settings['DEFAULT_FROM_EMAIL']
for user, i in msgs.iteritems:
if (not user.profile or not or not
with override(user.profile.language):
context = {'user': user, 'messages': i}
subject = ungettext("%d new notification",
"%d new notifications", len(i)) % len(i)
body = render_to_string('dashboard/notifications/email.txt',
send_mail(subject, body, from_email, (, ))
logger.error("Failed to send mail to", user, exc_info=True)
for j in i:
j.status = j.STATUS.delivered
......@@ -63,6 +63,12 @@ celery.conf.update(
'schedule': timedelta(hours=1),
'options': {'queue': ''}
'dashboard.local_periodic_tasks': {
'task': 'dashboard.tasks.local_periodic_tasks.'
'schedule': timedelta(hours=24),
'options': {'queue': ''}
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