FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
patchwork/patchwork/views/mail.py at main · getpatchwork/patchwork · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
getpatchwork
/
patchwork
Public
Notifications
You must be signed in to change notification settings
Fork
90
Star
315
Code
Issues
97
Pull requests
22
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
patchwork
/
patchwork
/
views
/
mail.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
124 lines (93 loc) · 3.43 KB
Breadcrumbs
patchwork
/
patchwork
/
views
/
mail.py
Copy path
File metadata and controls
124 lines (93 loc) · 3.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Patchwork - automated patch tracking system
# Copyright (C) 2010 Jeremy Kerr <jk@ozlabs.org>
#
# SPDX-License-Identifier: GPL-2.0-or-later
import
smtplib
from
django
.
conf
import
settings
as
conf_settings
from
django
.
core
.
mail
import
send_mail
from
django
.
http
import
HttpResponseRedirect
from
django
.
shortcuts
import
render
from
django
.
template
.
loader
import
render_to_string
from
django
.
urls
import
reverse
from
patchwork
.
forms
import
EmailForm
from
patchwork
.
models
import
EmailConfirmation
from
patchwork
.
models
import
EmailOptout
def
settings
(
request
):
if
request
.
method
==
'POST'
:
form
=
EmailForm
(
data
=
request
.
POST
)
if
form
.
is_valid
():
email
=
form
.
cleaned_data
[
'email'
]
is_optout
=
EmailOptout
.
objects
.
filter
(
email
=
email
).
count
()
>
0
context
=
{
'email'
:
email
,
'is_optout'
:
is_optout
,
}
return
render
(
request
,
'patchwork/mail-settings.html'
,
context
)
else
:
form
=
EmailForm
()
context
=
{
'form'
:
form
,
}
return
render
(
request
,
'patchwork/mail.html'
,
context
)
def
optout_confirm
(
request
,
conf
):
email
=
conf
.
email
.
strip
().
lower
()
# silently ignore duplicated optouts
if
EmailOptout
.
objects
.
filter
(
email
=
email
).
count
()
==
0
:
optout
=
EmailOptout
(
email
=
email
)
optout
.
save
()
conf
.
deactivate
()
context
=
{
'email'
:
conf
.
email
,
}
return
render
(
request
,
'patchwork/optout.html'
,
context
)
def
optin_confirm
(
request
,
conf
):
email
=
conf
.
email
.
strip
().
lower
()
EmailOptout
.
objects
.
filter
(
email
=
email
).
delete
()
conf
.
deactivate
()
context
=
{
'email'
:
conf
.
email
,
}
return
render
(
request
,
'patchwork/optin.html'
,
context
)
def
_optinout
(
request
,
action
):
context
=
{}
mail_template
=
'patchwork/mails/%s-request.txt'
%
action
mail_subject_template
=
'patchwork/mails/%s-request-subject.txt'
%
action
html_template
=
'patchwork/%s-request.html'
%
action
if
request
.
method
!=
'POST'
:
return
HttpResponseRedirect
(
reverse
(
settings
))
form
=
EmailForm
(
data
=
request
.
POST
)
if
not
form
.
is_valid
():
context
[
'error'
]
=
(
'There was an error in the form. Please review and re-submit.'
)
context
[
'form'
]
=
form
return
render
(
request
,
html_template
,
context
)
email
=
form
.
cleaned_data
[
'email'
]
if
(
action
==
'optin'
and
EmailOptout
.
objects
.
filter
(
email
=
email
).
count
()
==
0
):
context
[
'error'
]
=
(
'The email address %s is not on the patchwork '
"opt-out list, so you don't need to opt back in"
%
email
)
context
[
'form'
]
=
form
return
render
(
request
,
html_template
,
context
)
conf
=
EmailConfirmation
(
type
=
action
,
email
=
email
)
conf
.
save
()
context
[
'confirmation'
]
=
conf
subject
=
render_to_string
(
mail_subject_template
)
message
=
render_to_string
(
mail_template
,
context
,
request
=
request
)
try
:
send_mail
(
subject
,
message
,
conf_settings
.
DEFAULT_FROM_EMAIL
, [
email
])
except
smtplib
.
SMTPException
:
context
[
'confirmation'
]
=
None
context
[
'error'
]
=
(
'An error occurred during confirmation. Please try again later.'
)
context
[
'admins'
]
=
conf_settings
.
ADMINS
return
render
(
request
,
html_template
,
context
)
def
optout
(
request
):
return
_optinout
(
request
,
'optout'
)
def
optin
(
request
):
return
_optinout
(
request
,
'optin'
)
Back
|
FazBrowse Home
|
New Git URL