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
0d849903
Commit
0d849903
authored
1 year ago
by
George Katsikas
Browse files
Options
Downloads
Patches
Plain Diff
add multi-bcc capability to email form
parent
5c5b9e6d
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/common/forms.py
+13
-0
13 additions, 0 deletions
scipost_django/common/forms.py
scipost_django/mails/forms.py
+5
-3
5 additions, 3 deletions
scipost_django/mails/forms.py
with
18 additions
and
3 deletions
scipost_django/common/forms.py
+
13
−
0
View file @
0d849903
...
...
@@ -4,6 +4,8 @@ __license__ = "AGPL v3"
from
django
import
forms
from
crispy_forms.helper
import
FormHelper
from
django.core.validators
import
EmailValidator
from
django.forms
import
CharField
class
HTMXInlineCRUDModelForm
(
forms
.
ModelForm
):
...
...
@@ -16,3 +18,14 @@ class HTMXInlineCRUDModelForm(forms.ModelForm):
class
ModelChoiceFieldwithid
(
forms
.
ModelChoiceField
):
def
label_from_instance
(
self
,
obj
):
return
"
%s (id = %i)
"
%
(
super
().
label_from_instance
(
obj
),
obj
.
id
)
class
MultiEmailValidator
(
EmailValidator
):
def
__call__
(
self
,
mail_str
:
str
):
for
email
in
mail_str
.
split
(
"
,
"
):
super
().
__call__
(
email
.
strip
())
# Should not be an Email field because browser validation is unwanted.
class
MultiEmailField
(
CharField
):
default_validators
=
[
MultiEmailValidator
()]
This diff is collapsed.
Click to expand it.
scipost_django/mails/forms.py
+
5
−
3
View file @
0d849903
...
...
@@ -4,6 +4,8 @@ __license__ = "AGPL v3"
from
django
import
forms
from
common.forms
import
MultiEmailField
from
.core
import
MailEngine
from
.exceptions
import
ConfigurationError
from
.widgets
import
SummernoteEditor
...
...
@@ -17,7 +19,7 @@ class EmailForm(forms.Form):
subject
=
forms
.
CharField
(
max_length
=
255
,
label
=
"
Subject*
"
)
text
=
forms
.
CharField
(
widget
=
SummernoteEditor
,
label
=
"
Text*
"
)
mail_field
=
forms
.
EmailField
(
label
=
"
Optional: bcc this email to
"
,
required
=
False
)
mail_field
=
Multi
EmailField
(
label
=
"
Optional: bcc this email to
"
,
required
=
False
)
prefix
=
"
mail_form
"
extra_config
=
{}
...
...
@@ -73,8 +75,8 @@ class EmailForm(forms.Form):
def
save
(
self
):
self
.
engine
.
render_template
(
self
.
cleaned_data
[
"
text
"
])
self
.
engine
.
mail_data
[
"
subject
"
]
=
self
.
cleaned_data
[
"
subject
"
]
if
self
.
cleaned_data
[
"
mail_field
"
]:
self
.
engine
.
mail_data
[
"
bcc
"
]
.
append
(
self
.
cleaned_data
[
"
mail_field
"
])
if
bcc_mail_str
:
=
self
.
cleaned_data
[
"
mail_field
"
]:
self
.
engine
.
mail_data
[
"
bcc
"
]
+=
[
m
.
strip
()
for
m
in
bcc_mail_str
.
split
(
"
,
"
)]
self
.
engine
.
send_mail
()
return
self
.
engine
.
template_variables
[
"
object
"
]
...
...
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