Skip to content

Commit

Permalink
newforms-admin: Moved some views to contrib.auth. Based largely on a …
Browse files Browse the repository at this point in the history
…patch by Honza Kral.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6811 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jkocherhans committed Dec 1, 2007
1 parent 2d98a83 commit 8e2dfeb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion django/contrib/admin/sites.py
Expand Up @@ -171,7 +171,7 @@ def user_change_password(self, request, id):
"""
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):
Expand Down
29 changes: 1 addition & 28 deletions django/contrib/auth/models.py
Expand Up @@ -366,31 +366,4 @@ def is_authenticated(self):
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
37 changes: 35 additions & 2 deletions 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."
Expand Down Expand Up @@ -97,3 +100,33 @@ def password_change(request, template_name='registration/password_change_form.ht

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))

0 comments on commit 8e2dfeb

Please sign in to comment.