Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
MOOC packages by hacklab
django-courses
Commits
d4f0ff56
Commit
d4f0ff56
authored
Jun 11, 2020
by
Laury Bueno
Browse files
Merge branch 'develop'
parents
358a6f90
481204f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
6 deletions
+17
-6
courses/models.py
courses/models.py
+17
-6
No files found.
courses/models.py
View file @
d4f0ff56
...
...
@@ -662,18 +662,18 @@ class ProfessorMessage(models.Model):
related_name
=
'message_courses'
,
blank
=
True
,
)
def
send
(
self
):
# bcc = list with all destinataries
# batch = bcc.split( constant )
# for each batch ->
# for each batch ->
# send message
# save status
# if it goes wrong
# split batch by 2 and try it again (binary search)
# check if everything is sent
email_batch_size
=
settings
.
PROFESSOR_MESSAGE_CHUNK_SIZE
bcc
=
[
u
.
email
for
u
in
self
.
users
.
all
()
if
u
.
is_active
and
re
.
match
(
r
"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
,
u
.
email
)]
try
:
et
=
EmailTemplate
.
objects
.
get
(
name
=
'professor-message'
)
...
...
@@ -681,9 +681,20 @@ class ProfessorMessage(models.Model):
et
=
EmailTemplate
(
name
=
"professor-message"
,
subject
=
"{{subject}}"
,
template
=
"{{message|safe}}"
)
subject
=
Template
(
et
.
subject
).
render
(
Context
({
'subject'
:
self
.
subject
}))
message
=
Template
(
et
.
template
).
render
(
Context
({
'message'
:
self
.
message
}))
email
=
EmailMessage
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
,
[
settings
.
DEFAULT_FROM_EMAIL
,
],
bcc
)
email
.
content_subtype
=
"html"
return
email
.
send
()
# Iterate over the bcc list to send emails in chunks
# Maximum chunk size is email_batch_size
start
=
0
end
=
min
(
email_batch_size
,
len
(
bcc
))
while
start
<
len
(
bcc
):
email
=
EmailMessage
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
,
[
settings
.
DEFAULT_FROM_EMAIL
,
],
bcc
[
start
:
end
])
email
.
content_subtype
=
"html"
email
.
send
()
start
=
end
end
=
min
(
end
+
email_batch_size
,
len
(
bcc
))
return
None
class
ProfessorMessageRead
(
models
.
Model
):
...
...
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