Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6742cbb2
authored
Jun 07, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: fix send_email_notifications implementation
parent
5d9f0a4a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
7 deletions
+16
-7
circle/dashboard/tasks/local_periodic_tasks.py
+16
-7
No files found.
circle/dashboard/tasks/local_periodic_tasks.py
View file @
6742cbb2
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
import
logging
import
logging
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.mail
import
send_mail
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.template.loader
import
render_to_string
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
ungettext
,
override
from
django.utils.translation
import
ungettext
,
override
...
@@ -31,20 +33,25 @@ logger = logging.getLogger(__name__)
...
@@ -31,20 +33,25 @@ logger = logging.getLogger(__name__)
@celery.task
(
ignore_result
=
True
)
@celery.task
(
ignore_result
=
True
)
def
send_email_notifications
():
def
send_email_notifications
():
msgs
=
{}
msgs
=
{}
for
i
in
Notification
.
objects
.
filter
(
status
=
Notification
.
STATUS
.
new
,
q
=
Q
(
status
=
Notification
.
STATUS
.
new
)
&
(
valid_until__lt
=
timezone
.
now
()):
Q
(
valid_until__lt
=
timezone
.
now
())
|
Q
(
valid_until
=
None
))
for
i
in
Notification
.
objects
.
filter
(
q
):
if
i
.
to
not
in
msgs
:
if
i
.
to
not
in
msgs
:
msgs
[
i
.
to
]
=
[]
msgs
[
i
.
to
]
=
[]
msgs
[
i
.
to
]
.
append
(
i
)
msgs
[
i
.
to
]
.
append
(
i
)
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
user
.
email
or
not
if
(
not
user
.
profile
or
not
user
.
email
or
not
user
.
profile
.
email_notifications
):
user
.
profile
.
email_notifications
):
logger
.
debug
(
"
%
s gets no notifications"
,
unicode
(
user
))
continue
continue
with
override
(
user
.
profile
.
language
):
with
override
(
user
.
profile
.
preferred_language
):
context
=
{
'user'
:
user
,
'messages'
:
i
}
context
=
{
'user'
:
user
.
profile
,
'messages'
:
i
,
'url'
:
(
settings
.
DJANGO_URL
.
rstrip
(
"/"
)
+
reverse
(
"dashboard.views.notifications"
)),
'site'
:
settings
.
COMPANY_NAME
}
subject
=
ungettext
(
"
%
d new notification"
,
subject
=
ungettext
(
"
%
d new notification"
,
"
%
d new notifications"
,
len
(
i
))
%
len
(
i
)
"
%
d new notifications"
,
len
(
i
))
%
len
(
i
)
body
=
render_to_string
(
'dashboard/notifications/email.txt'
,
body
=
render_to_string
(
'dashboard/notifications/email.txt'
,
...
@@ -52,8 +59,10 @@ def send_email_notifications():
...
@@ -52,8 +59,10 @@ def send_email_notifications():
try
:
try
:
send_mail
(
subject
,
body
,
from_email
,
(
user
.
email
,
))
send_mail
(
subject
,
body
,
from_email
,
(
user
.
email
,
))
except
:
except
:
logger
.
error
(
"Failed to send mail to"
,
user
,
exc_info
=
True
)
logger
.
error
(
"Failed to send mail to
%
s
"
,
user
,
exc_info
=
True
)
else
:
else
:
logger
.
info
(
"Delivered notifications
%
s"
,
" "
.
join
(
j
.
pk
for
j
in
i
))
for
j
in
i
:
for
j
in
i
:
j
.
status
=
j
.
STATUS
.
delivered
j
.
status
=
j
.
STATUS
.
delivered
j
.
save
()
j
.
save
()
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