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 e.j.postma+django-trac@…, 18 years ago)

Preliminary patch (untested)

  • django/django/contrib/auth/views.py

     
    22from django.contrib.auth.forms import PasswordResetForm, PasswordChangeForm
    33from django import oldforms
    44from django.shortcuts import render_to_response
    5 from django.template import RequestContext
     5from django.template import loader, RequestContext
    66from django.contrib.sites.models import Site
    7 from django.http import HttpResponseRedirect
     7from django.http import HttpResponse, HttpResponseRedirect
    88from django.contrib.auth.decorators import login_required
    99from django.contrib.auth import REDIRECT_FIELD_NAME
    1010
    11 def login(request, template_name='registration/login.html'):
     11def login(request, template_name='registration/login.html', template_loader=loader):
    1212    "Displays the login form and handles the login action."
    1313    manipulator = AuthenticationForm(request)
    1414    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
     
    2626    else:
    2727        errors = {}
    2828    request.session.set_test_cookie()
    29     return render_to_response(template_name, {
     29    context = RequestContext(request, {
    3030        'form': oldforms.FormWrapper(manipulator, request.POST, errors),
    3131        REDIRECT_FIELD_NAME: redirect_to,
    3232        '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))
    3436
    35 def logout(request, next_page=None, template_name='registration/logged_out.html'):
     37def logout(request, next_page=None, template_name='registration/logged_out.html',
     38           template_loader=loader):
    3639    "Logs out the user and displays 'You are logged out' message."
    3740    from django.contrib.auth import logout
    3841    logout(request)
    3942    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))
    4146    else:
    4247        # Redirect to this page until the session has been cleared.
    4348        return HttpResponseRedirect(next_page or request.path)
     
    5762    return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, next))
    5863
    5964def 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):
    6166    new_data, errors = {}, {}
    6267    form = PasswordResetForm()
    6368    if request.POST:
     
    6974            else:
    7075                form.save(email_template_name=email_template_name)
    7176            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))
    7481
    75 def password_reset_done(request, template_name='registration/password_reset_done.html'):
    76     return render_to_response(template_name, context_instance=RequestContext(request))
     82def 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))
    7787
    78 def password_change(request, template_name='registration/password_change_form.html'):
     88def password_change(request, template_name='registration/password_change_form.html',
     89        template_loader=loader):
    7990    new_data, errors = {}, {}
    8091    form = PasswordChangeForm(request.user)
    8192    if request.POST:
     
    8495        if not errors:
    8596            form.save(new_data)
    8697            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))
    89102password_change = login_required(password_change)
    90103
    91 def password_change_done(request, template_name='registration/password_change_done.html'):
    92     return render_to_response(template_name, context_instance=RequestContext(request))
     104def 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))
Back to Top