From b54f3d05cd8ae11b36065f0ce16dd44db5cf1d77 Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Wed, 11 Dec 2013 14:32:13 +0000 Subject: [PATCH] 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 --- django/contrib/admin/sites.py | 15 +++++++++------ django/contrib/admin/templates/admin/base.html | 2 ++ django/contrib/auth/forms.py | 8 ++++---- django/contrib/auth/models.py | 4 ++-- django/core/serializers/json.py | 2 ++ django/db/models/query.py | 5 ++--- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index e0f43dfbf..bbb97abed 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -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'), diff --git a/django/contrib/admin/templates/admin/base.html b/django/contrib/admin/templates/admin/base.html index 63d4419fa..f35121bf2 100644 --- a/django/contrib/admin/templates/admin/base.html +++ b/django/contrib/admin/templates/admin/base.html @@ -32,9 +32,11 @@ {% if docsroot %} {% trans 'Documentation' %} / {% endif %} + {% comment %} {% if user.has_usable_password %} {% trans 'Change password' %} / {% endif %} + {% endcomment %} {% trans 'Log out' %} {% endblock %} diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 081d9e558..d5e869311 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -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 " diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index 51537530e..b7b7b036f 100644 --- a/django/contrib/auth/models.py +++ b/django/contrib/auth/models.py @@ -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') diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py index 64357bf9d..1cdd6f3b6 100644 --- a/django/core/serializers/json.py +++ b/django/core/serializers/json.py @@ -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) diff --git a/django/db/models/query.py b/django/db/models/query.py index 1075407ae..4bc2df5c8 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -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))