#22752: PasswordResetForm email context is missing current_app
-------------------------------+--------------------
     Reporter:  bendavis78     |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  contrib.auth   |    Version:  master
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  1              |      UI/UX:  0
-------------------------------+--------------------
 I have multiple namespace instances for password reset urls. The email
 template rendered by the default PasswordResetForm does not included a
 `current_app` context. It's an easy fix, though, ass the PasswordResetForm
 already has `self.current_app`. Just need to wrap the context instance
 passed to the email template:

 {{{
 #!diff
 diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
 index 6e07d45..baef873 100644
 --- a/django/contrib/auth/forms.py
 +++ b/django/contrib/auth/forms.py
 @@ -4,7 +4,7 @@ from collections import OrderedDict

  from django import forms
  from django.forms.utils import flatatt
 -from django.template import loader
 +from django.template import loader, Context
  from django.utils.encoding import force_bytes
  from django.utils.html import format_html, format_html_join
  from django.utils.http import urlsafe_base64_encode
 @@ -264,10 +264,13 @@ class PasswordResetForm(forms.Form):
                  'token': token_generator.make_token(user),
                  'protocol': 'https' if use_https else 'http',
              }
 -            subject = loader.render_to_string(subject_template_name, c)
 +            context_instance = Context(current_app=self.current_app)
 +            subject = loader.render_to_string(
 +                subject_template_name, c, context_instance)
              # Email subject *must not* contain newlines
              subject = ''.join(subject.splitlines())
 -            email = loader.render_to_string(email_template_name, c)
 +            email = loader.render_to_string(
 +                email_template_name, c, context_instance)

              if html_email_template_name:
                  html_email =
 loader.render_to_string(html_email_template_name, c)
 ~
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22752>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.e9b491401308056935aff3766eab00cc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to