summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2007-12-01 20:51:53 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2007-12-01 20:51:53 +0000
commit8e2dfebc7233f6e47786e20314ee684afd0a0fa1 (patch)
tree82a38193fa7e4839205ce32e8e91cc7aea90cf57
parent2d98a8391834421fba7dfb09be501524b70f9fc2 (diff)
newforms-admin: Moved some views to contrib.auth. Based largely on a patch by Honza Kral.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6811 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/admin/sites.py2
-rw-r--r--django/contrib/auth/models.py29
-rw-r--r--django/contrib/auth/views.py37
3 files changed, 37 insertions, 31 deletions
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index 471678f199..4e95a06bba 100644
--- a/django/contrib/admin/sites.py
+++ b/django/contrib/admin/sites.py
@@ -171,7 +171,7 @@ class AdminSite(object):
"""
Handles the "user change password" task
"""
- from django.contrib.admin.views.auth import user_change_password
+ from django.contrib.auth.views import user_change_password
return user_change_password(request, id)
def i18n_javascript(self, request):
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index e694c7614f..22e0078744 100644
--- a/django/contrib/auth/models.py
+++ b/django/contrib/auth/models.py
@@ -366,31 +366,4 @@ class AnonymousUser(object):
return False
# Register the admin options for these models.
-# TODO: Maybe this should live in a separate module admin.py, but how would we
-# ensure that module was loaded?
-
-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):
- from django.contrib.admin.views.auth import user_add_stage
- return user_add_stage(request)
-
-admin.site.register(Group, GroupAdmin)
-admin.site.register(User, UserAdmin)
+from django.contrib.auth import admin
diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
index d3d8b4ccb7..509b96ee64 100644
--- a/django/contrib/auth/views.py
+++ b/django/contrib/auth/views.py
@@ -1,13 +1,16 @@
from django.contrib.auth.forms import AuthenticationForm
-from django.contrib.auth.forms import PasswordResetForm, PasswordChangeForm
+from django.contrib.auth.forms import PasswordResetForm, PasswordChangeForm, AdminPasswordChangeForm
+from django.core.exceptions import PermissionDenied
from django import oldforms
-from django.shortcuts import render_to_response
+from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.contrib.sites.models import Site, RequestSite
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.contrib.auth import REDIRECT_FIELD_NAME
+from django.utils.html import escape
from django.utils.translation import ugettext as _
+from django.contrib.auth.models import User
def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME):
"Displays the login form and handles the login action."
@@ -97,3 +100,33 @@ password_change = login_required(password_change)
def password_change_done(request, template_name='registration/password_change_done.html'):
return render_to_response(template_name, context_instance=RequestContext(request))
+
+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=RequestContext(request))