[Django] #22752: PasswordResetForm email context is missing current_app

8 views
Skip to first unread message

Django

unread,
Jun 2, 2014, 4:00:38 PM6/2/14
to django-...@googlegroups.com
#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.

Django

unread,
Jun 2, 2014, 4:02:41 PM6/2/14
to django-...@googlegroups.com
#22752: PasswordResetForm email context is missing current_app
-------------------------------+--------------------------------------

Reporter: bendavis78 | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by bendavis78):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Correction, PasswordResetForm does not have current_app built in. That
needs to be added as well.

--
Ticket URL: <https://code.djangoproject.com/ticket/22752#comment:1>

Django

unread,
Jun 2, 2014, 4:02:42 PM6/2/14
to django-...@googlegroups.com
#22752: PasswordResetForm email context is missing current_app
-------------------------------+--------------------------------------

Reporter: bendavis78 | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by bendavis78):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Correction, PasswordResetForm does not have current_app built in. That
needs to be added as well.

--
Ticket URL: <https://code.djangoproject.com/ticket/22752#comment:2>

Django

unread,
Jun 14, 2014, 7:06:56 AM6/14/14
to django-...@googlegroups.com
#22752: PasswordResetForm email context is missing current_app
-------------------------------+--------------------------------------

Reporter: bendavis78 | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.auth | Version: master
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
-------------------------------+--------------------------------------
Changes (by EvilDMP):

* needs_better_patch: => 0
* needs_tests: => 0

* easy: 1 => 0
* needs_docs: => 0


Django

unread,
Jun 14, 2014, 8:30:21 AM6/14/14
to django-...@googlegroups.com
#22752: PasswordResetForm email context is missing current_app
--------------------------------------+------------------------------------
Reporter: bendavis78 | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by bmispelon):

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
* needs_docs: 0 => 1
* has_patch: 0 => 1
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

Hi,

I agree that it would be good to have the current app while rendering the
body of the email because it would help with reversing URLs inside it.
However, I don't really understand the use-case behind having the current
app when rendering the subject line.

In any case, the provided patch doesn't apply on master and it's also
going to require tests and documentation.

Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/22752#comment:3>

Django

unread,
Jun 25, 2014, 2:34:44 PM6/25/14
to django-...@googlegroups.com
#22752: PasswordResetForm email context is missing current_app
--------------------------------------+------------------------------------
Reporter: bendavis78 | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.auth | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by bendavis78):

@bmispelon, I think one would expect the context to be identical in both
the body and the subject. Whether or not there's a use case, I can't think
of any justification for making them separate. I plan on working on this
(as well as various other tickets I've submitted) once I get a little more
free time.

--
Ticket URL: <https://code.djangoproject.com/ticket/22752#comment:4>

Django

unread,
Jun 25, 2014, 2:35:58 PM6/25/14
to django-...@googlegroups.com
#22752: PasswordResetForm email context is missing current_app
--------------------------------------+------------------------------------
Reporter: bendavis78 | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.auth | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by bendavis78):

* cc: bendavis78 (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/22752#comment:5>

Django

unread,
Aug 28, 2019, 11:04:21 AM8/28/19
to django-...@googlegroups.com
#22752: PasswordResetForm email context is missing current_app
-------------------------------------+-------------------------------------
Reporter: Ben Davis | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* owner: nobody => Hasan Ramezani
* status: new => assigned


Comment:

@felixxm Do we still need this ticket?

--
Ticket URL: <https://code.djangoproject.com/ticket/22752#comment:6>

Django

unread,
Jan 18, 2021, 9:27:04 PM1/18/21
to django-...@googlegroups.com
#22752: Allow PasswordResetForm email to render URLs based on the current namespace

-------------------------------------+-------------------------------------
Reporter: Ben Davis | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 1 => 0
* has_patch: 1 => 0
* needs_tests: 1 => 0
* needs_docs: 1 => 0


Comment:

`current_app` is no longer an argument to `render_to_string()` but I think
this would be resolved by passing `request` instead (which can be passed
to `send_mail()` from `save()`). The `url` template tag uses the namespace
of the currently resolved view as the current application in a
`RequestContext`.

--
Ticket URL: <https://code.djangoproject.com/ticket/22752#comment:7>

Reply all
Reply to author
Forward
0 new messages