Ticket #8379: r8520-validate-username.patch

File r8520-validate-username.patch, 1.9 KB (added by Ivan Giuliani, 16 years ago)
  • django/contrib/auth/admin.py

     
    1 
    21from django.contrib.auth.models import User, Group
    32from django.core.exceptions import PermissionDenied
    43from django import template
     
    76from django.utils.html import escape
    87from django.http import HttpResponseRedirect
    98from django.utils.translation import ugettext, ugettext_lazy as _
    10 from django.contrib.auth.forms import UserCreationForm, AdminPasswordChangeForm
     9from django.contrib.auth.forms import UserCreationForm, UserChangeForm, AdminPasswordChangeForm
    1110from django.contrib import admin
    1211
    1312class GroupAdmin(admin.ModelAdmin):
     
    2322        (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
    2423        (_('Groups'), {'fields': ('groups',)}),
    2524    )
     25    form = UserChangeForm
    2626    add_form = UserCreationForm
    2727    change_password_form = AdminPasswordChangeForm
    2828    list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
  • django/contrib/auth/forms.py

     
    4343            user.save()
    4444        return user
    4545
     46class UserChangeForm(forms.ModelForm):
     47    username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^\w+$',
     48        help_text = _("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."),
     49        error_message = _("This value must contain only letters, numbers and underscores."))
     50
     51    class Meta:
     52        model = User
     53
    4654class AuthenticationForm(forms.Form):
    4755    """
    4856    Base class for authenticating users. Extend this to get a form that accepts
Back to Top