Ticket #7932: user_model_admin_subclass.diff

File user_model_admin_subclass.diff, 2.1 KB (added by ElliottM, 16 years ago)
  • django/contrib/auth/admin.py

     
    11from django.contrib.auth.models import User, Group
     2from django.contrib.auth.forms import UserCreationForm
    23from django.core.exceptions import PermissionDenied
    34from django import template
    45from django.shortcuts import render_to_response
     
    2425    search_fields = ('username', 'first_name', 'last_name', 'email')
    2526    ordering = ('username',)
    2627    filter_horizontal = ('user_permissions',)
     28
     29    creation_form=UserCreationForm
    2730
    2831    def add_view(self, request):
    29         # avoid a circular import. see #6718.
    30         from django.contrib.auth.forms import UserCreationForm
    3132        if not self.has_change_permission(request):
    3233            raise PermissionDenied
    3334        if request.method == 'POST':
    34             form = UserCreationForm(request.POST)
     35            form = self.creation_form(request.POST)
    3536            if form.is_valid():
    3637                new_user = form.save()
    3738                msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': 'user', 'obj': new_user}
     
    4243                    request.user.message_set.create(message=msg + ' ' + ugettext("You may edit it again below."))
    4344                    return HttpResponseRedirect('../%s/' % new_user.id)
    4445        else:
    45             form = UserCreationForm()
     46            form = self.creation_form()
    4647        return render_to_response('admin/auth/user/add_form.html', {
    4748            'title': _('Add user'),
    4849            'form': form,
     
    5556            'has_file_field': False,
    5657            'has_absolute_url': False,
    5758            'auto_populated_fields': (),
    58             'opts': User._meta,
     59            'opts': self.model._meta,
    5960            'save_as': False,
    60             'username_help_text': User._meta.get_field('username').help_text,
     61            'username_help_text': self.model._meta.get_field('username').help_text,
    6162            'root_path': self.admin_site.root_path,
    6263        }, context_instance=template.RequestContext(request))
    6364
Back to Top