Ticket #7932: user_model_admin_subclass.diff
File user_model_admin_subclass.diff, 2.1 KB (added by , 16 years ago) |
---|
-
django/contrib/auth/admin.py
1 1 from django.contrib.auth.models import User, Group 2 from django.contrib.auth.forms import UserCreationForm 2 3 from django.core.exceptions import PermissionDenied 3 4 from django import template 4 5 from django.shortcuts import render_to_response … … 24 25 search_fields = ('username', 'first_name', 'last_name', 'email') 25 26 ordering = ('username',) 26 27 filter_horizontal = ('user_permissions',) 28 29 creation_form=UserCreationForm 27 30 28 31 def add_view(self, request): 29 # avoid a circular import. see #6718.30 from django.contrib.auth.forms import UserCreationForm31 32 if not self.has_change_permission(request): 32 33 raise PermissionDenied 33 34 if request.method == 'POST': 34 form = UserCreationForm(request.POST)35 form = self.creation_form(request.POST) 35 36 if form.is_valid(): 36 37 new_user = form.save() 37 38 msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': 'user', 'obj': new_user} … … 42 43 request.user.message_set.create(message=msg + ' ' + ugettext("You may edit it again below.")) 43 44 return HttpResponseRedirect('../%s/' % new_user.id) 44 45 else: 45 form = UserCreationForm()46 form = self.creation_form() 46 47 return render_to_response('admin/auth/user/add_form.html', { 47 48 'title': _('Add user'), 48 49 'form': form, … … 55 56 'has_file_field': False, 56 57 'has_absolute_url': False, 57 58 'auto_populated_fields': (), 58 'opts': User._meta,59 'opts': self.model._meta, 59 60 '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, 61 62 'root_path': self.admin_site.root_path, 62 63 }, context_instance=template.RequestContext(request)) 63 64