SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SciPost
SciPost
Commits
989c65ac
Commit
989c65ac
authored
1 year ago
by
George Katsikas
Browse files
Options
Downloads
Patches
Plain Diff
rework email sender to allow for mails -if they exist-
parent
7b71d2b9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scipost_django/mails/core.py
+18
-11
18 additions, 11 deletions
scipost_django/mails/core.py
scipost_django/templates/email/fellowship_nominees/fellowship_invitation_initial.json
+1
-1
1 addition, 1 deletion
...il/fellowship_nominees/fellowship_invitation_initial.json
with
19 additions
and
12 deletions
scipost_django/mails/core.py
+
18
−
11
View file @
989c65ac
...
...
@@ -42,7 +42,7 @@ class MailEngine:
bcc
=
[],
from_email
=
""
,
from_name
=
""
,
**
kwargs
**
kwargs
,
):
"""
Start engine with specific mail_code. Any other keyword argument that is passed will
...
...
@@ -257,17 +257,21 @@ class MailEngine:
def
_validate_email_fields
(
self
):
"""
Validate all email addresses in the mail config.
"""
for
email_key
in
self
.
_email_fields
:
if
email_key
in
self
.
mail_data
:
if
isinstance
(
self
.
mail_data
[
email_key
],
list
):
for
i
,
email
in
enumerate
(
self
.
mail_data
[
email_key
]):
self
.
mail_data
[
email_key
][
i
]
=
self
.
_validate_email_addresses
(
email
)
else
:
self
.
mail_data
[
email_key
]
=
self
.
_validate_email_addresses
(
self
.
mail_data
[
email_key
]
if
emails
:
=
self
.
mail_data
.
get
(
email_key
,
None
):
emails
=
emails
if
isinstance
(
emails
,
list
)
else
[
emails
]
valid_emails
=
[
valid_entry
for
entry
in
emails
if
(
valid_entry
:
=
self
.
_validate_email_addresses
(
entry
))
]
if
len
(
valid_emails
)
==
0
:
raise
ConfigurationError
(
"
No valid email addresses found for %s.
"
%
email_key
)
self
.
mail_data
[
email_key
]
=
valid_emails
def
_validate_email_addresses
(
self
,
entry
):
"""
Return email address given raw email, email prefix or database relation given in `entry`.
...
...
@@ -280,13 +284,16 @@ class MailEngine:
return
"
%s%s
"
%
(
entry
,
get_current_domain
())
elif
self
.
template_variables
[
"
object
"
]:
mail_to
=
self
.
template_variables
[
"
object
"
]
for
attr
in
entry
.
split
(
"
.
"
):
for
attr
in
entry
.
split
(
"
|
"
)[
0
].
split
(
"
.
"
):
try
:
mail_to
=
getattr
(
mail_to
,
attr
)
if
inspect
.
ismethod
(
mail_to
):
mail_to
=
mail_to
()
except
AttributeError
:
# Invalid property/mail
if
entry
.
endswith
(
"
|None
"
):
# Allow None values
return
None
raise
KeyError
(
"
The property (%s) does not exist.
"
%
entry
)
return
mail_to
raise
KeyError
(
"
Neither an email adress nor db instance is given.
"
)
This diff is collapsed.
Click to expand it.
scipost_django/templates/email/fellowship_nominees/fellowship_invitation_initial.json
+
1
−
1
View file @
989c65ac
...
...
@@ -2,7 +2,7 @@
"subject"
:
"Invitation to become a Fellow at SciPost"
,
"recipient_list"
:
[
"nomination.profile.email"
,
"nomination.profile.contributor.user.email"
"nomination.profile.contributor.user.email
|None
"
],
"bcc"
:
[
"edadmin@"
...
...
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