Ticket #5298: contrib_auth_views_extra_context.patch

File contrib_auth_views_extra_context.patch, 5.9 KB (added by efloehr, 5 years ago)

Patch for extra_context, current as of changeset [13042]

  • django/contrib/auth/views.py

     
    2222@never_cache
    2323def login(request, template_name='registration/login.html',
    2424          redirect_field_name=REDIRECT_FIELD_NAME,
    25           authentication_form=AuthenticationForm):
     25          authentication_form=AuthenticationForm,
     26          extra_context=None):
    2627    """Displays the login form and handles the login action."""
    2728
    2829    redirect_to = request.REQUEST.get(redirect_field_name, '')
     
    6465        redirect_field_name: redirect_to,
    6566        'site': current_site,
    6667        'site_name': current_site.name,
    67     }, context_instance=RequestContext(request))
     68    }, context_instance=RequestContext(request, extra_context))
    6869
    69 def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME):
     70def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME, extra_context=None):
    7071    "Logs out the user and displays 'You are logged out' message."
    7172    from django.contrib.auth import logout
    7273    logout(request)
     
    7778        else:
    7879            return render_to_response(template_name, {
    7980                'title': _('Logged out')
    80             }, context_instance=RequestContext(request))
     81            }, context_instance=RequestContext(request, extra_context))
    8182    else:
    8283        # Redirect to this page until the session has been cleared.
    8384        return HttpResponseRedirect(next_page or request.path)
    8485
    85 def logout_then_login(request, login_url=None):
     86def logout_then_login(request, login_url=None, extra_context=None):
    8687    "Logs out the user if he is logged in. Then redirects to the log-in page."
    8788    if not login_url:
    8889        login_url = settings.LOGIN_URL
    89     return logout(request, login_url)
     90    return logout(request, login_url, extra_context=extra_context)
    9091
    9192def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
    9293    "Redirects the user to the login page, passing the given 'next' page"
     
    105106def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html',
    106107        email_template_name='registration/password_reset_email.html',
    107108        password_reset_form=PasswordResetForm, token_generator=default_token_generator,
    108         post_reset_redirect=None):
     109        post_reset_redirect=None, extra_context=None):
    109110    if post_reset_redirect is None:
    110111        post_reset_redirect = reverse('django.contrib.auth.views.password_reset_done')
    111112    if request.method == "POST":
     
    126127        form = password_reset_form()
    127128    return render_to_response(template_name, {
    128129        'form': form,
    129     }, context_instance=RequestContext(request))
     130    }, context_instance=RequestContext(request, extra_context))
    130131
    131 def password_reset_done(request, template_name='registration/password_reset_done.html'):
    132     return render_to_response(template_name, context_instance=RequestContext(request))
     132def password_reset_done(request, template_name='registration/password_reset_done.html', extra_context=None):
     133    return render_to_response(template_name, context_instance=RequestContext(request, extra_context))
    133134
    134135# Doesn't need csrf_protect since no-one can guess the URL
    135136def password_reset_confirm(request, uidb36=None, token=None, template_name='registration/password_reset_confirm.html',
    136137                           token_generator=default_token_generator, set_password_form=SetPasswordForm,
    137                            post_reset_redirect=None):
     138                           post_reset_redirect=None, extra_context=None):
    138139    """
    139140    View that checks the hash in a password reset link and presents a
    140141    form for entering a new password.
     
    163164        context_instance['validlink'] = False
    164165        form = None
    165166    context_instance['form'] = form
    166     return render_to_response(template_name, context_instance=context_instance)
     167    return render_to_response(template_name, context_instance=context_instance, extra_context=extra_context)
    167168
    168 def password_reset_complete(request, template_name='registration/password_reset_complete.html'):
    169     return render_to_response(template_name, context_instance=RequestContext(request,
    170                                                                              {'login_url': settings.LOGIN_URL}))
     169def password_reset_complete(request, template_name='registration/password_reset_complete.html', extra_context=None):
     170    context = {'login_url': settings.LOGIN_URL}
     171    if extra_context: context.update(extra_context)
     172    return render_to_response(template_name, context_instance=RequestContext(request, context))
    171173
    172174@csrf_protect
    173175@login_required
    174176def password_change(request, template_name='registration/password_change_form.html',
    175                     post_change_redirect=None, password_change_form=PasswordChangeForm):
     177                    post_change_redirect=None, password_change_form=PasswordChangeForm, extra_context=None):
    176178    if post_change_redirect is None:
    177179        post_change_redirect = reverse('django.contrib.auth.views.password_change_done')
    178180    if request.method == "POST":
     
    184186        form = password_change_form(user=request.user)
    185187    return render_to_response(template_name, {
    186188        'form': form,
    187     }, context_instance=RequestContext(request))
     189    }, context_instance=RequestContext(request, extra_context))
    188190
    189 def password_change_done(request, template_name='registration/password_change_done.html'):
    190     return render_to_response(template_name, context_instance=RequestContext(request))
     191def password_change_done(request, template_name='registration/password_change_done.html', extra_context=None):
     192    return render_to_response(template_name, context_instance=RequestContext(request, extra_context))
Back to Top