Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django/contrib/auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class UserChangeForm(forms.ModelForm):
password = ReadOnlyPasswordHashField(label=_("Password"),
help_text=_("Raw passwords are not stored, so there is no way to see "
"this user's password, but you can change the password "
"using <a href=\"password/\">this form</a>."))
"using <a href=\"../password/\">this form</a>."))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the following be considered over-engineered?

from django.core.urlresolvers import reverse
from django.utils.functional import lazy
from django.utils import six
from django.utils.translation import ugettext

def _password_helptext():
    message = ugettext('...using <a href="%(password_change_url)s">this form</a>')
    password_change_url = reverse('password_change')
    return message % {'password_change_url': password_change_url}
password_helptext = lazy(_password_helptext, six.text_type)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that we are not talking about password_change, but auth_user_password_change which takes the user pk as argument, and that complicates things a bit more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I see, didn't realize that.


class Meta:
model = User
Expand Down
19 changes: 17 additions & 2 deletions tests/auth_tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import datetime
import itertools
import os
import re
from importlib import import_module

Expand Down Expand Up @@ -943,14 +944,28 @@ def test_user_not_change(self):
self.assertEqual(row.change_message, 'No fields changed.')

def test_user_change_password(self):
user_change_url = reverse('auth_test_admin:auth_user_change', args=(self.admin.pk,))
password_change_url = reverse('auth_test_admin:auth_user_password_change', args=(self.admin.pk,))

response = self.client.get(user_change_url)
# Test the link inside password field help_text.
rel_link = re.search(
r'you can change the password using <a href="([^"]*)">this form</a>',
force_text(response.content)
).groups()[0]
self.assertEqual(
os.path.normpath(user_change_url + rel_link),
os.path.normpath(password_change_url)
)

response = self.client.post(
reverse('auth_test_admin:auth_user_password_change', args=(self.admin.pk,)),
password_change_url,
{
'password1': 'password1',
'password2': 'password1',
}
)
self.assertRedirects(response, reverse('auth_test_admin:auth_user_change', args=(self.admin.pk,)))
self.assertRedirects(response, user_change_url)
row = LogEntry.objects.latest('id')
self.assertEqual(row.change_message, 'Changed password.')
self.logout()
Expand Down