Ticket #5298: contrib_auth_views_extra_context.patch
File contrib_auth_views_extra_context.patch, 5.9 KB (added by , 15 years ago) |
---|
-
django/contrib/auth/views.py
22 22 @never_cache 23 23 def login(request, template_name='registration/login.html', 24 24 redirect_field_name=REDIRECT_FIELD_NAME, 25 authentication_form=AuthenticationForm): 25 authentication_form=AuthenticationForm, 26 extra_context=None): 26 27 """Displays the login form and handles the login action.""" 27 28 28 29 redirect_to = request.REQUEST.get(redirect_field_name, '') … … 64 65 redirect_field_name: redirect_to, 65 66 'site': current_site, 66 67 'site_name': current_site.name, 67 }, context_instance=RequestContext(request ))68 }, context_instance=RequestContext(request, extra_context)) 68 69 69 def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME ):70 def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME, extra_context=None): 70 71 "Logs out the user and displays 'You are logged out' message." 71 72 from django.contrib.auth import logout 72 73 logout(request) … … 77 78 else: 78 79 return render_to_response(template_name, { 79 80 'title': _('Logged out') 80 }, context_instance=RequestContext(request ))81 }, context_instance=RequestContext(request, extra_context)) 81 82 else: 82 83 # Redirect to this page until the session has been cleared. 83 84 return HttpResponseRedirect(next_page or request.path) 84 85 85 def logout_then_login(request, login_url=None ):86 def logout_then_login(request, login_url=None, extra_context=None): 86 87 "Logs out the user if he is logged in. Then redirects to the log-in page." 87 88 if not login_url: 88 89 login_url = settings.LOGIN_URL 89 return logout(request, login_url )90 return logout(request, login_url, extra_context=extra_context) 90 91 91 92 def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): 92 93 "Redirects the user to the login page, passing the given 'next' page" … … 105 106 def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html', 106 107 email_template_name='registration/password_reset_email.html', 107 108 password_reset_form=PasswordResetForm, token_generator=default_token_generator, 108 post_reset_redirect=None ):109 post_reset_redirect=None, extra_context=None): 109 110 if post_reset_redirect is None: 110 111 post_reset_redirect = reverse('django.contrib.auth.views.password_reset_done') 111 112 if request.method == "POST": … … 126 127 form = password_reset_form() 127 128 return render_to_response(template_name, { 128 129 'form': form, 129 }, context_instance=RequestContext(request ))130 }, context_instance=RequestContext(request, extra_context)) 130 131 131 def password_reset_done(request, template_name='registration/password_reset_done.html' ):132 return render_to_response(template_name, context_instance=RequestContext(request ))132 def 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)) 133 134 134 135 # Doesn't need csrf_protect since no-one can guess the URL 135 136 def password_reset_confirm(request, uidb36=None, token=None, template_name='registration/password_reset_confirm.html', 136 137 token_generator=default_token_generator, set_password_form=SetPasswordForm, 137 post_reset_redirect=None ):138 post_reset_redirect=None, extra_context=None): 138 139 """ 139 140 View that checks the hash in a password reset link and presents a 140 141 form for entering a new password. … … 163 164 context_instance['validlink'] = False 164 165 form = None 165 166 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) 167 168 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})) 169 def 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)) 171 173 172 174 @csrf_protect 173 175 @login_required 174 176 def 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): 176 178 if post_change_redirect is None: 177 179 post_change_redirect = reverse('django.contrib.auth.views.password_change_done') 178 180 if request.method == "POST": … … 184 186 form = password_change_form(user=request.user) 185 187 return render_to_response(template_name, { 186 188 'form': form, 187 }, context_instance=RequestContext(request ))189 }, context_instance=RequestContext(request, extra_context)) 188 190 189 def password_change_done(request, template_name='registration/password_change_done.html' ):190 return render_to_response(template_name, context_instance=RequestContext(request ))191 def 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))