Ticket #5298: auth-extra-content-14586.diff

File auth-extra-content-14586.diff, 6.4 KB (added by Adam Vandenberg, 14 years ago)

Patch updated to r14586

  • django/contrib/auth/views.py

    diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
    index 5b306e4..6f19080 100644
    a b from django.views.decorators.cache import never_cache  
    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, '')
    def login(request, template_name='registration/login.html',  
    6162        redirect_field_name: redirect_to,
    6263        'site': current_site,
    6364        'site_name': current_site.name,
    64     }, context_instance=RequestContext(request))
     65    }, context_instance=RequestContext(request, extra_context))
    6566
    66 def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME):
     67def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME, extra_context=None):
    6768    "Logs out the user and displays 'You are logged out' message."
    6869    from django.contrib.auth import logout
    6970    logout(request)
    def logout(request, next_page=None, template_name='registration/logged_out.html'  
    7778                'site': current_site,
    7879                'site_name': current_site.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"
    def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_N  
    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, from_email=None):
     109        post_reset_redirect=None, from_email=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":
    def password_reset(request, is_admin_site=False, template_name='registration/pas  
    125126        form = password_reset_form()
    126127    return render_to_response(template_name, {
    127128        'form': form,
    128     }, context_instance=RequestContext(request))
     129    }, context_instance=RequestContext(request, extra_context))
    129130
    130 def password_reset_done(request, template_name='registration/password_reset_done.html'):
    131     return render_to_response(template_name, context_instance=RequestContext(request))
     131def password_reset_done(request, template_name='registration/password_reset_done.html', extra_context=None):
     132    return render_to_response(template_name, context_instance=RequestContext(request, extra_context))
    132133
    133134# Doesn't need csrf_protect since no-one can guess the URL
    134135def password_reset_confirm(request, uidb36=None, token=None, template_name='registration/password_reset_confirm.html',
    135136                           token_generator=default_token_generator, set_password_form=SetPasswordForm,
    136                            post_reset_redirect=None):
     137                           post_reset_redirect=None, extra_context=None):
    137138    """
    138139    View that checks the hash in a password reset link and presents a
    139140    form for entering a new password.
    def password_reset_confirm(request, uidb36=None, token=None, template_name='regi  
    162163        context_instance['validlink'] = False
    163164        form = None
    164165    context_instance['form'] = form
    165     return render_to_response(template_name, context_instance=context_instance)
     166    return render_to_response(template_name, context_instance=context_instance, extra_context=extra_context)
    166167
    167 def password_reset_complete(request, template_name='registration/password_reset_complete.html'):
    168     return render_to_response(template_name, context_instance=RequestContext(request,
    169                                                                              {'login_url': settings.LOGIN_URL}))
     168def password_reset_complete(request, template_name='registration/password_reset_complete.html', extra_context=None):
     169    context = {'login_url': settings.LOGIN_URL}
     170    if extra_context: context.update(extra_context)
     171    return render_to_response(template_name, context_instance=RequestContext(request, context))
    170172
    171173@csrf_protect
    172174@login_required
    173175def password_change(request, template_name='registration/password_change_form.html',
    174                     post_change_redirect=None, password_change_form=PasswordChangeForm):
     176                    post_change_redirect=None, password_change_form=PasswordChangeForm, extra_context=None):
    175177    if post_change_redirect is None:
    176178        post_change_redirect = reverse('django.contrib.auth.views.password_change_done')
    177179    if request.method == "POST":
    def password_change(request, template_name='registration/password_change_form.ht  
    183185        form = password_change_form(user=request.user)
    184186    return render_to_response(template_name, {
    185187        'form': form,
    186     }, context_instance=RequestContext(request))
     188    }, context_instance=RequestContext(request, extra_context))
    187189
    188 def password_change_done(request, template_name='registration/password_change_done.html'):
    189     return render_to_response(template_name, context_instance=RequestContext(request))
     190def password_change_done(request, template_name='registration/password_change_done.html', extra_context=None):
     191    return render_to_response(template_name, context_instance=RequestContext(request, extra_context))
Back to Top