Ticket #5298: fix-extra_context.diff

File fix-extra_context.diff, 3.9 KB (added by jordanl, 17 years ago)

Adds support for passing extra_context to the views in django.contrib.auth.views

  • django/contrib/auth/views.py

     
    99from django.contrib.auth import REDIRECT_FIELD_NAME
    1010from django.utils.translation import ugettext as _
    1111
    12 def login(request, template_name='registration/login.html'):
     12def login(request, template_name='registration/login.html', extra_context={}):
    1313    "Displays the login form and handles the login action."
    1414    manipulator = AuthenticationForm(request)
    1515    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
     
    3737        'form': oldforms.FormWrapper(manipulator, request.POST, errors),
    3838        REDIRECT_FIELD_NAME: redirect_to,
    3939        'site_name': current_site.name,
    40     }, context_instance=RequestContext(request))
     40    }, context_instance=RequestContext(request, extra_context))
    4141
    42 def logout(request, next_page=None, template_name='registration/logged_out.html'):
     42def logout(request, next_page=None, template_name='registration/logged_out.html', extra_context={}):
    4343    "Logs out the user and displays 'You are logged out' message."
    4444    from django.contrib.auth import logout
    4545    logout(request)
    4646    if next_page is None:
    47         return render_to_response(template_name, {'title': _('Logged out')}, context_instance=RequestContext(request))
     47        return render_to_response(template_name, {'title': _('Logged out')}, context_instance=RequestContext(request, extra_context))
    4848    else:
    4949        # Redirect to this page until the session has been cleared.
    5050        return HttpResponseRedirect(next_page or request.path)
     
    6464    return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, next))
    6565
    6666def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html',
    67         email_template_name='registration/password_reset_email.html'):
     67        email_template_name='registration/password_reset_email.html', extra_context={}):
    6868    new_data, errors = {}, {}
    6969    form = PasswordResetForm()
    7070    if request.POST:
     
    7777                form.save(email_template_name=email_template_name)
    7878            return HttpResponseRedirect('%sdone/' % request.path)
    7979    return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)},
    80         context_instance=RequestContext(request))
     80        context_instance=RequestContext(request, extra_context))
    8181
    82 def password_reset_done(request, template_name='registration/password_reset_done.html'):
    83     return render_to_response(template_name, context_instance=RequestContext(request))
     82def password_reset_done(request, template_name='registration/password_reset_done.html', extra_context={}):
     83    return render_to_response(template_name, context_instance=RequestContext(request, extra_context))
    8484
    85 def password_change(request, template_name='registration/password_change_form.html'):
     85def password_change(request, template_name='registration/password_change_form.html', extra_context={}):
    8686    new_data, errors = {}, {}
    8787    form = PasswordChangeForm(request.user)
    8888    if request.POST:
     
    9292            form.save(new_data)
    9393            return HttpResponseRedirect('%sdone/' % request.path)
    9494    return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)},
    95         context_instance=RequestContext(request))
     95        context_instance=RequestContext(request, extra_context))
    9696password_change = login_required(password_change)
    9797
    98 def password_change_done(request, template_name='registration/password_change_done.html'):
    99     return render_to_response(template_name, context_instance=RequestContext(request))
     98def password_change_done(request, template_name='registration/password_change_done.html', extra_context={}):
     99    return render_to_response(template_name, context_instance=RequestContext(request, extra_context))
Back to Top