Redo non-obsoleted patches to Django - hiding password change in admin, username max_length, JSON serialization of timedelta and debug hack to DoesNotExist so .get() shows the kwargs

- Legacy-Id: 6873
This commit is contained in:
Ole Laursen 2013-12-11 14:32:13 +00:00
parent 73f3ce0905
commit b54f3d05cd
6 changed files with 21 additions and 15 deletions

View file

@ -223,12 +223,12 @@ class AdminSite(object):
url(r'^logout/$',
wrap(self.logout),
name='logout'),
url(r'^password_change/$',
wrap(self.password_change, cacheable=True),
name='password_change'),
url(r'^password_change/done/$',
wrap(self.password_change_done, cacheable=True),
name='password_change_done'),
#url(r'^password_change/$',
# wrap(self.password_change, cacheable=True),
# name='password_change'),
#url(r'^password_change/done/$',
# wrap(self.password_change_done, cacheable=True),
# name='password_change_done'),
url(r'^jsi18n/$',
wrap(self.i18n_javascript, cacheable=True),
name='jsi18n'),
@ -313,6 +313,9 @@ class AdminSite(object):
"""
Displays the login form for the given HttpRequest.
"""
url = "/accounts/login/?next="+request.get_full_path()
return http.HttpResponseRedirect(url)
from django.contrib.auth.views import login
context = {
'title': _('Log in'),

View file

@ -32,9 +32,11 @@
{% if docsroot %}
<a href="{{ docsroot }}">{% trans 'Documentation' %}</a> /
{% endif %}
{% comment %}
{% if user.has_usable_password %}
<a href="{% url 'admin:password_change' %}">{% trans 'Change password' %}</a> /
{% endif %}
{% endcomment %}
<a href="{% url 'admin:logout' %}">{% trans 'Log out' %}</a>
{% endblock %}
</div>

View file

@ -73,9 +73,9 @@ class UserCreationForm(forms.ModelForm):
'duplicate_username': _("A user with that username already exists."),
'password_mismatch': _("The two password fields didn't match."),
}
username = forms.RegexField(label=_("Username"), max_length=30,
username = forms.RegexField(label=_("Username"), max_length=64,
regex=r'^[\w.@+-]+$',
help_text=_("Required. 30 characters or fewer. Letters, digits and "
help_text=_("Required. 64 characters or fewer. Letters, digits and "
"@/./+/-/_ only."),
error_messages={
'invalid': _("This value may contain only letters, numbers and "
@ -123,8 +123,8 @@ class UserCreationForm(forms.ModelForm):
class UserChangeForm(forms.ModelForm):
username = forms.RegexField(
label=_("Username"), max_length=30, regex=r"^[\w.@+-]+$",
help_text=_("Required. 30 characters or fewer. Letters, digits and "
label=_("Username"), max_length=64, regex=r"^[\w.@+-]+$",
help_text=_("Required. 64 characters or fewer. Letters, digits and "
"@/./+/-/_ only."),
error_messages={
'invalid': _("This value may contain only letters, numbers and "

View file

@ -365,8 +365,8 @@ class AbstractUser(AbstractBaseUser, PermissionsMixin):
Username, password and email are required. Other fields are optional.
"""
username = models.CharField(_('username'), max_length=30, unique=True,
help_text=_('Required. 30 characters or fewer. Letters, numbers and '
username = models.CharField(_('username'), max_length=64, unique=True,
help_text=_('Required. 64 characters or fewer. Letters, numbers and '
'@/./+/-/_ characters'),
validators=[
validators.RegexValidator(re.compile('^[\w.@+-]+$'), _('Enter a valid username.'), 'invalid')

View file

@ -100,6 +100,8 @@ class DjangoJSONEncoder(json.JSONEncoder):
return r
elif isinstance(o, decimal.Decimal):
return str(o)
elif isinstance(o, datetime.timedelta):
return o.days * 24*60*60 + o.seconds
else:
return super(DjangoJSONEncoder, self).default(o)

View file

@ -302,9 +302,8 @@ class QuerySet(object):
if num == 1:
return clone._result_cache[0]
if not num:
raise self.model.DoesNotExist(
"%s matching query does not exist." %
self.model._meta.object_name)
raise self.model.DoesNotExist(u"%s matching query does not exist. Lookup parameters were %s"
% (self.model._meta.object_name, kwargs))
raise self.model.MultipleObjectsReturned(
"get() returned more than one %s -- it returned %s!" %
(self.model._meta.object_name, num))