Ticket #11514: auth_extra_context.diff

File auth_extra_context.diff, 6.3 KB (added by Adam Vandenberg, 15 years ago)

Initial stab at a patch.

  • django/contrib/auth/views.py

     
    1414from django.contrib.auth.models import User
    1515from django.views.decorators.cache import never_cache
    1616
    17 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME):
     17def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME, extra_context=None):
    1818    "Displays the login form and handles the login action."
    1919    redirect_to = request.REQUEST.get(redirect_field_name, '')
    2020    if request.method == "POST":
     
    3535        current_site = Site.objects.get_current()
    3636    else:
    3737        current_site = RequestSite(request)
    38     return render_to_response(template_name, {
     38       
     39    context = {
    3940        'form': form,
    4041        redirect_field_name: redirect_to,
    4142        'site': current_site,
    4243        'site_name': current_site.name,
    43     }, context_instance=RequestContext(request))
     44    }
     45    context.update(extra_context or {})
     46    return render_to_response(template_name, context, context_instance=RequestContext(request))
    4447login = never_cache(login)
    4548
    46 def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME):
     49def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME,
     50        extra_context=None):
    4751    "Logs out the user and displays 'You are logged out' message."
    4852    from django.contrib.auth import logout
    4953    logout(request)
     
    5256        if redirect_to:
    5357            return HttpResponseRedirect(redirect_to)
    5458        else:
    55             return render_to_response(template_name, {
    56                 'title': _('Logged out')
    57             }, context_instance=RequestContext(request))
     59            context = {'title': _('Logged out')}
     60            context.update(extra_context or {})
     61            return render_to_response(template_name, context, context_instance=RequestContext(request))
    5862    else:
    5963        # Redirect to this page until the session has been cleared.
    6064        return HttpResponseRedirect(next_page or request.path)
     
    8185def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html',
    8286        email_template_name='registration/password_reset_email.html',
    8387        password_reset_form=PasswordResetForm, token_generator=default_token_generator,
    84         post_reset_redirect=None):
     88        post_reset_redirect=None, extra_context=None):
    8589    if post_reset_redirect is None:
    8690        post_reset_redirect = reverse('django.contrib.auth.views.password_reset_done')
    8791    if request.method == "POST":
     
    100104            return HttpResponseRedirect(post_reset_redirect)
    101105    else:
    102106        form = password_reset_form()
    103     return render_to_response(template_name, {
    104         'form': form,
    105     }, context_instance=RequestContext(request))
     107    context = { 'form': form }
     108    context.update(extra_context or {})
     109    return render_to_response(template_name, context, context_instance=RequestContext(request))
    106110
    107 def password_reset_done(request, template_name='registration/password_reset_done.html'):
    108     return render_to_response(template_name, context_instance=RequestContext(request))
     111def password_reset_done(request, template_name='registration/password_reset_done.html', extra_context=None):
     112    context = extra_context or {}
     113    return render_to_response(template_name, context, context_instance=RequestContext(request))
    109114
    110115def password_reset_confirm(request, uidb36=None, token=None, template_name='registration/password_reset_confirm.html',
    111116                           token_generator=default_token_generator, set_password_form=SetPasswordForm,
    112                            post_reset_redirect=None):
     117                           post_reset_redirect=None, extra_context=None):
    113118    """
    114119    View that checks the hash in a password reset link and presents a
    115120    form for entering a new password.
     
    137142    else:
    138143        context_instance['validlink'] = False
    139144        form = None
    140     context_instance['form'] = form   
    141     return render_to_response(template_name, context_instance=context_instance)
     145    context_instance['form'] = form
     146    context = extra_context or {}
     147    return render_to_response(template_name, context, context_instance=context_instance)
    142148
    143 def password_reset_complete(request, template_name='registration/password_reset_complete.html'):
    144     return render_to_response(template_name, context_instance=RequestContext(request,
    145                                                                              {'login_url': settings.LOGIN_URL}))
     149def password_reset_complete(request, template_name='registration/password_reset_complete.html', extra_context=None):
     150    context = extra_context or {}
     151    return render_to_response(template_name, context,
     152        context_instance=RequestContext(request, {'login_url': settings.LOGIN_URL}))
    146153
    147154def password_change(request, template_name='registration/password_change_form.html',
    148                     post_change_redirect=None):
     155                    post_change_redirect=None, extra_context=None):
    149156    if post_change_redirect is None:
    150157        post_change_redirect = reverse('django.contrib.auth.views.password_change_done')
    151158    if request.method == "POST":
     
    155162            return HttpResponseRedirect(post_change_redirect)
    156163    else:
    157164        form = PasswordChangeForm(request.user)
    158     return render_to_response(template_name, {
    159         'form': form,
    160     }, context_instance=RequestContext(request))
     165    context = { 'form': form }
     166    context.update(extra_context or {})
     167    return render_to_response(template_name, context, context_instance=RequestContext(request))
    161168password_change = login_required(password_change)
    162169
    163 def password_change_done(request, template_name='registration/password_change_done.html'):
    164     return render_to_response(template_name, context_instance=RequestContext(request))
     170def password_change_done(request, template_name='registration/password_change_done.html', extra_context=None):
     171    context = extra_context or {}
     172    return render_to_response(template_name, context, context_instance=RequestContext(request))
Back to Top