#36110: Unable to customize kwargs passed to PasswordResetForm
EmailMultiAlternatives
------------------------------+--------------------------------------
Reporter: Claude Paroz | Owner: (none)
Type: New feature | Status: new
Component: contrib.auth | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Comment (by Claude Paroz):
Note I didn't pass through a forum post as I think the need is rather
straightforward. You may disagree :-)
A possible implementation:
{{{
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
index cd177fa5b6..56fedc4ae7 100644
--- a/django/contrib/auth/forms.py
+++ b/django/contrib/auth/forms.py
@@ -402,6 +402,14 @@ class PasswordResetForm(forms.Form):
widget=forms.EmailInput(attrs={"autocomplete": "email"}),
)
+ def extra_email_kwargs(self):
+ """
+ Allow setting extra EmailMultiAlternatives init parameters, after
the
+ first four parameters (subject, body, from_email, to) which are
defined
+ inside the send_mail() method.
+ """
+ return {}
+
def send_mail(
self,
subject_template_name,
@@ -419,7 +427,7 @@ class PasswordResetForm(forms.Form):
subject = "".join(subject.splitlines())
body = loader.render_to_string(email_template_name, context)
- email_message = EmailMultiAlternatives(subject, body, from_email,
[to_email])
+ email_message = EmailMultiAlternatives(subject, body, from_email,
[to_email], **self.extra_email_kwargs())
if html_email_template_name is not None:
html_email =
loader.render_to_string(html_email_template_name, context)
email_message.attach_alternative(html_email, "text/html")
}}}
--
Ticket URL: <
https://code.djangoproject.com/ticket/36110#comment:1>