Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

newforms-admin: Should have been part of [6811].

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6812 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 42bd0c6ebac19d16e983bd8bf17970feab8ce229 1 parent 8e2dfeb
@jkocherhans jkocherhans authored
Showing with 64 additions and 76 deletions.
  1. +0 −76 django/contrib/admin/views/auth.py
  2. +64 −0 django/contrib/auth/admin.py
View
76 django/contrib/admin/views/auth.py
@@ -1,76 +0,0 @@
-from django.contrib.admin.views.decorators import staff_member_required
-from django.contrib.auth.forms import UserCreationForm, AdminPasswordChangeForm
-from django.contrib.auth.models import User
-from django.core.exceptions import PermissionDenied
-from django import oldforms, template
-from django.shortcuts import render_to_response, get_object_or_404
-from django.http import HttpResponseRedirect
-from django.utils.html import escape
-from django.utils.translation import ugettext as _
-
-def user_add_stage(request):
- if not request.user.has_perm('auth.change_user'):
- raise PermissionDenied
- manipulator = UserCreationForm()
- if request.method == 'POST':
- new_data = request.POST.copy()
- errors = manipulator.get_validation_errors(new_data)
- if not errors:
- new_user = manipulator.save(new_data)
- msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': 'user', 'obj': new_user}
- if "_addanother" in request.POST:
- request.user.message_set.create(message=msg)
- return HttpResponseRedirect(request.path)
- else:
- request.user.message_set.create(message=msg + ' ' + _("You may edit it again below."))
- return HttpResponseRedirect('../%s/' % new_user.id)
- else:
- errors = new_data = {}
- form = oldforms.FormWrapper(manipulator, new_data, errors)
- return render_to_response('admin/auth/user/add_form.html', {
- 'title': _('Add user'),
- 'form': form,
- 'is_popup': '_popup' in request.REQUEST,
- 'add': True,
- 'change': False,
- 'has_add_permission': True,
- 'has_delete_permission': False,
- 'has_change_permission': True,
- 'has_file_field': False,
- 'has_absolute_url': False,
- 'auto_populated_fields': (),
- 'opts': User._meta,
- 'username_help_text': User._meta.get_field('username').help_text,
- }, context_instance=template.RequestContext(request))
-user_add_stage = staff_member_required(user_add_stage)
-
-def user_change_password(request, id):
- if not request.user.has_perm('auth.change_user'):
- raise PermissionDenied
- user = get_object_or_404(User, pk=id)
- manipulator = AdminPasswordChangeForm(user)
- if request.method == 'POST':
- new_data = request.POST.copy()
- errors = manipulator.get_validation_errors(new_data)
- if not errors:
- new_user = manipulator.save(new_data)
- msg = _('Password changed successfully.')
- request.user.message_set.create(message=msg)
- return HttpResponseRedirect('..')
- else:
- errors = new_data = {}
- form = oldforms.FormWrapper(manipulator, new_data, errors)
- return render_to_response('admin/auth/user/change_password.html', {
- 'title': _('Change password: %s') % escape(user.username),
- 'form': form,
- 'is_popup': '_popup' in request.REQUEST,
- 'add': True,
- 'change': False,
- 'has_delete_permission': False,
- 'has_change_permission': True,
- 'has_absolute_url': False,
- 'opts': User._meta,
- 'original': user,
- 'show_save': True,
- }, context_instance=template.RequestContext(request))
-user_change_password = staff_member_required(user_change_password)
View
64 django/contrib/auth/admin.py
@@ -0,0 +1,64 @@
+from django.contrib.auth.forms import UserCreationForm
+from django.contrib.auth.models import User, Group
+from django.core.exceptions import PermissionDenied
+from django import oldforms, template
+from django.shortcuts import render_to_response
+from django.http import HttpResponseRedirect
+from django.utils.translation import ugettext, ugettext_lazy as _
+from django.contrib import admin
+
+class GroupAdmin(admin.ModelAdmin):
+ search_fields = ('name',)
+ filter_horizontal = ('permissions',)
+
+class UserAdmin(admin.ModelAdmin):
+ fieldsets = (
+ (None, {'fields': ('username', 'password')}),
+ (_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
+ (_('Permissions'), {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}),
+ (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
+ (_('Groups'), {'fields': ('groups',)}),
+ )
+ list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
+ list_filter = ('is_staff', 'is_superuser')
+ search_fields = ('username', 'first_name', 'last_name', 'email')
+ filter_horizontal = ('user_permissions',)
+
+ def add_view(self, request):
+ if not self.has_change_permission(request):
+ raise PermissionDenied
+ manipulator = UserCreationForm()
+ if request.method == 'POST':
+ new_data = request.POST.copy()
+ errors = manipulator.get_validation_errors(new_data)
+ if not errors:
+ new_user = manipulator.save(new_data)
+ msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': 'user', 'obj': new_user}
+ if "_addanother" in request.POST:
+ request.user.message_set.create(message=msg)
+ return HttpResponseRedirect(request.path)
+ else:
+ request.user.message_set.create(message=msg + ' ' + ugettext("You may edit it again below."))
+ return HttpResponseRedirect('../%s/' % new_user.id)
+ else:
+ errors = new_data = {}
+ form = oldforms.FormWrapper(manipulator, new_data, errors)
+ return render_to_response('admin/auth/user/add_form.html', {
+ 'title': _('Add user'),
+ 'form': form,
+ 'is_popup': '_popup' in request.REQUEST,
+ 'add': True,
+ 'change': False,
+ 'has_add_permission': True,
+ 'has_delete_permission': False,
+ 'has_change_permission': True,
+ 'has_file_field': False,
+ 'has_absolute_url': False,
+ 'auto_populated_fields': (),
+ 'opts': User._meta,
+ 'username_help_text': User._meta.get_field('username').help_text,
+ }, context_instance=template.RequestContext(request))
+
+admin.site.register(Group, GroupAdmin)
+admin.site.register(User, UserAdmin)
+
Please sign in to comment.
Something went wrong with that request. Please try again.