Ticket #4247: make-django.contrib.auth.views-accept-template_loader.diff
File make-django.contrib.auth.views-accept-template_loader.diff, 5.0 KB (added by , 18 years ago) |
---|
-
django/django/contrib/auth/views.py
2 2 from django.contrib.auth.forms import PasswordResetForm, PasswordChangeForm 3 3 from django import oldforms 4 4 from django.shortcuts import render_to_response 5 from django.template import RequestContext5 from django.template import loader, RequestContext 6 6 from django.contrib.sites.models import Site 7 from django.http import HttpResponse Redirect7 from django.http import HttpResponse, HttpResponseRedirect 8 8 from django.contrib.auth.decorators import login_required 9 9 from django.contrib.auth import REDIRECT_FIELD_NAME 10 10 11 def login(request, template_name='registration/login.html' ):11 def login(request, template_name='registration/login.html', template_loader=loader): 12 12 "Displays the login form and handles the login action." 13 13 manipulator = AuthenticationForm(request) 14 14 redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '') … … 26 26 else: 27 27 errors = {} 28 28 request.session.set_test_cookie() 29 return render_to_response(template_name, {29 context = RequestContext(request, { 30 30 'form': oldforms.FormWrapper(manipulator, request.POST, errors), 31 31 REDIRECT_FIELD_NAME: redirect_to, 32 32 'site_name': Site.objects.get_current().name, 33 }, context_instance=RequestContext(request)) 33 }) 34 t = template_loader.get_template(template_name) 35 return HttpResponse(t.render(context)) 34 36 35 def logout(request, next_page=None, template_name='registration/logged_out.html'): 37 def logout(request, next_page=None, template_name='registration/logged_out.html', 38 template_loader=loader): 36 39 "Logs out the user and displays 'You are logged out' message." 37 40 from django.contrib.auth import logout 38 41 logout(request) 39 42 if next_page is None: 40 return render_to_response(template_name, {'title': _('Logged out')}, context_instance=RequestContext(request)) 43 context = RequestContext(request, {'title': _('Logged out')}) 44 t = template_loader.get_template(template_name) 45 return HttpResponse(t.render(context)) 41 46 else: 42 47 # Redirect to this page until the session has been cleared. 43 48 return HttpResponseRedirect(next_page or request.path) … … 57 62 return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, next)) 58 63 59 64 def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html', 60 email_template_name='registration/password_reset_email.html' ):65 email_template_name='registration/password_reset_email.html', template_loader=loader): 61 66 new_data, errors = {}, {} 62 67 form = PasswordResetForm() 63 68 if request.POST: … … 69 74 else: 70 75 form.save(email_template_name=email_template_name) 71 76 return HttpResponseRedirect('%sdone/' % request.path) 72 return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)}, 73 context_instance=RequestContext(request)) 77 context = RequestContext(request, 78 {'form': oldforms.FormWrapper(form, new_data, errors)}) 79 t = template_loader.get_template(template_name) 80 return HttpResponse(t.render(context)) 74 81 75 def password_reset_done(request, template_name='registration/password_reset_done.html'): 76 return render_to_response(template_name, context_instance=RequestContext(request)) 82 def password_reset_done(request, template_name='registration/password_reset_done.html', 83 template_loader=loader): 84 context = RequestContext(request) 85 t = template_loader.get_template(template_name) 86 return HttpResponse(t.render(context)) 77 87 78 def password_change(request, template_name='registration/password_change_form.html'): 88 def password_change(request, template_name='registration/password_change_form.html', 89 template_loader=loader): 79 90 new_data, errors = {}, {} 80 91 form = PasswordChangeForm(request.user) 81 92 if request.POST: … … 84 95 if not errors: 85 96 form.save(new_data) 86 97 return HttpResponseRedirect('%sdone/' % request.path) 87 return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)}, 88 context_instance=RequestContext(request)) 98 context = RequestContext(request, 99 {'form': oldforms.FormWrapper(form, new_data, errors)}) 100 t = template_loader.get_template(template_name) 101 return HttpResponse(t.render(context)) 89 102 password_change = login_required(password_change) 90 103 91 def password_change_done(request, template_name='registration/password_change_done.html'): 92 return render_to_response(template_name, context_instance=RequestContext(request)) 104 def password_change_done(request, template_name='registration/password_change_done.html', 105 template_loader=loader): 106 context = RequestContext(request) 107 t = template_loader.get_template(template_name) 108 return HttpResponse(t.render(context))