Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
greg
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
it-bott-integrasjoner
greg
Commits
61c2a8b6
Commit
61c2a8b6
authored
3 years ago
by
Stein Elgethun
Browse files
Options
Downloads
Patches
Plain Diff
Use django-q to create tasks when sending mail
Isuse: GREG-66
parent
7f754ae0
No related branches found
No related tags found
1 merge request
!98
Greg 66 mail queue
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gregui/mailutils.py
+19
-13
19 additions, 13 deletions
gregui/mailutils.py
gregui/tests/test_mailutils.py
+5
-2
5 additions, 2 deletions
gregui/tests/test_mailutils.py
with
24 additions
and
15 deletions
gregui/mailutils.py
+
19
−
13
View file @
61c2a8b6
from
django.conf
import
settings
from
django.core.mail
import
send_mail
from
django.template.loader
import
render_to_string
from
django_q.tasks
import
async_task
def
registration_template
(
institution
,
sponsor
)
->
str
:
...
...
@@ -17,19 +17,25 @@ def confirmation_template(guest) -> str:
return
render_to_string
(
"
sponsor_confirmation.txt
"
,
keywords
)
def
send_registration_mail
(
mail_to
,
sponsor
)
->
int
:
return
send_mail
(
subject
=
"
Subject
"
,
message
=
registration_template
(
settings
.
INSTANCE_NAME
,
sponsor
),
from_email
=
None
,
recipient_list
=
[
mail_to
],
def
send_registration_mail
(
mail_to
,
sponsor
)
->
str
:
return
async_task
(
"
django.core.mail.send_mail
"
,
**
{
"
subject
"
:
"
Subject
"
,
"
message
"
:
registration_template
(
settings
.
INSTANCE_NAME
,
sponsor
),
"
from_email
"
:
None
,
"
recipient_list
"
:
[
mail_to
],
}
)
def
send_confirmation_mail
(
mail_to
,
guest
)
->
int
:
return
send_mail
(
subject
=
"
Subject
"
,
message
=
confirmation_template
(
guest
),
from_email
=
None
,
recipient_list
=
[
mail_to
],
def
send_confirmation_mail
(
mail_to
,
guest
)
->
str
:
return
async_task
(
"
django.core.mail.send_mail
"
,
**
{
"
subject
"
:
"
Subject
"
,
"
message
"
:
confirmation_template
(
guest
),
"
from_email
"
:
None
,
"
recipient_list
"
:
[
mail_to
],
}
)
This diff is collapsed.
Click to expand it.
gregui/tests/test_mailutils.py
+
5
−
2
View file @
61c2a8b6
from
django.core
import
mail
from
django_q.tasks
import
result
import
pytest
from
gregui
import
mailutils
...
...
@@ -33,7 +34,8 @@ Your guest, Foo Bar, has completed their registration, please confirm the guest
@pytest.mark.django_db
def
test_registration_mail
():
mail
.
outbox
=
[]
assert
mailutils
.
send_registration_mail
(
"
test@example.no
"
,
"
Foo
"
)
==
1
task_id
=
mailutils
.
send_registration_mail
(
"
test@example.no
"
,
"
Foo
"
)
assert
result
(
task_id
)
==
1
assert
len
(
mail
.
outbox
)
==
1
assert
mail
.
outbox
[
0
].
to
==
[
"
test@example.no
"
]
...
...
@@ -41,6 +43,7 @@ def test_registration_mail():
@pytest.mark.django_db
def
test_confirmation_mail
():
mail
.
outbox
=
[]
assert
mailutils
.
send_confirmation_mail
(
"
test@example.no
"
,
"
Foo
"
)
==
1
task_id
=
mailutils
.
send_confirmation_mail
(
"
test@example.no
"
,
"
Foo
"
)
assert
result
(
task_id
)
==
1
assert
len
(
mail
.
outbox
)
==
1
assert
mail
.
outbox
[
0
].
to
==
[
"
test@example.no
"
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment