Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e0199de6
authored
Jun 07, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: send collected notifications in mail
parent
e4141022
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
1 deletions
+69
-1
circle/dashboard/forms.py
+1
-1
circle/dashboard/migrations/0008_auto__add_field_profile_email_notifications.py
+0
-0
circle/dashboard/models.py
+3
-0
circle/dashboard/tasks/local_periodic_tasks.py
+59
-0
circle/manager/mancelery.py
+6
-0
No files found.
circle/dashboard/forms.py
View file @
e0199de6
...
...
@@ -1092,7 +1092,7 @@ class TraitForm(forms.ModelForm):
class
MyProfileForm
(
forms
.
ModelForm
):
class
Meta
:
fields
=
(
'preferred_language'
,
)
fields
=
(
'preferred_language'
,
'email_notifications'
,
)
model
=
Profile
@property
...
...
circle/dashboard/migrations/0008_auto__add_field_profile_email_notifications.py
0 → 100644
View file @
e0199de6
This diff is collapsed.
Click to expand it.
circle/dashboard/models.py
View file @
e0199de6
...
...
@@ -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
,
...
...
circle/dashboard/tasks/local_periodic_tasks.py
0 → 100644
View file @
e0199de6
# 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 <http://www.gnu.org/licenses/>.
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__
)
@celery.task
(
ignore_result
=
True
)
def
send_email_notifications
():
msgs
=
{}
for
i
in
Notification
.
objects
.
filter
(
status
=
Notification
.
STATUS
.
new
,
valid_until__lt
=
timezone
.
now
()):
if
i
.
to
not
in
msgs
:
msgs
[
i
.
to
]
=
[]
msgs
[
i
.
to
]
.
append
(
i
)
from_email
=
settings
[
'DEFAULT_FROM_EMAIL'
]
for
user
,
i
in
msgs
.
iteritems
:
if
(
not
user
.
profile
or
not
user
.
email
or
not
user
.
profile
.
email_notifications
):
continue
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'
,
context
)
try
:
send_mail
(
subject
,
body
,
from_email
,
(
user
.
email
,
))
except
:
logger
.
error
(
"Failed to send mail to"
,
user
,
exc_info
=
True
)
else
:
for
j
in
i
:
j
.
status
=
j
.
STATUS
.
delivered
j
.
save
()
circle/manager/mancelery.py
View file @
e0199de6
...
...
@@ -63,6 +63,12 @@ celery.conf.update(
'schedule'
:
timedelta
(
hours
=
1
),
'options'
:
{
'queue'
:
'localhost.man'
}
},
'dashboard.local_periodic_tasks'
:
{
'task'
:
'dashboard.tasks.local_periodic_tasks.'
'send_email_notifications'
,
'schedule'
:
timedelta
(
hours
=
24
),
'options'
:
{
'queue'
:
'localhost.man'
}
},
}
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment