Ticket #11514: auth_extra_context.diff
File auth_extra_context.diff, 6.3 KB (added by , 15 years ago) |
---|
-
django/contrib/auth/views.py
14 14 from django.contrib.auth.models import User 15 15 from django.views.decorators.cache import never_cache 16 16 17 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME ):17 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME, extra_context=None): 18 18 "Displays the login form and handles the login action." 19 19 redirect_to = request.REQUEST.get(redirect_field_name, '') 20 20 if request.method == "POST": … … 35 35 current_site = Site.objects.get_current() 36 36 else: 37 37 current_site = RequestSite(request) 38 return render_to_response(template_name, { 38 39 context = { 39 40 'form': form, 40 41 redirect_field_name: redirect_to, 41 42 'site': current_site, 42 43 '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)) 44 47 login = never_cache(login) 45 48 46 def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME): 49 def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME, 50 extra_context=None): 47 51 "Logs out the user and displays 'You are logged out' message." 48 52 from django.contrib.auth import logout 49 53 logout(request) … … 52 56 if redirect_to: 53 57 return HttpResponseRedirect(redirect_to) 54 58 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)) 58 62 else: 59 63 # Redirect to this page until the session has been cleared. 60 64 return HttpResponseRedirect(next_page or request.path) … … 81 85 def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html', 82 86 email_template_name='registration/password_reset_email.html', 83 87 password_reset_form=PasswordResetForm, token_generator=default_token_generator, 84 post_reset_redirect=None ):88 post_reset_redirect=None, extra_context=None): 85 89 if post_reset_redirect is None: 86 90 post_reset_redirect = reverse('django.contrib.auth.views.password_reset_done') 87 91 if request.method == "POST": … … 100 104 return HttpResponseRedirect(post_reset_redirect) 101 105 else: 102 106 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)) 106 110 107 def password_reset_done(request, template_name='registration/password_reset_done.html'): 108 return render_to_response(template_name, context_instance=RequestContext(request)) 111 def 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)) 109 114 110 115 def password_reset_confirm(request, uidb36=None, token=None, template_name='registration/password_reset_confirm.html', 111 116 token_generator=default_token_generator, set_password_form=SetPasswordForm, 112 post_reset_redirect=None ):117 post_reset_redirect=None, extra_context=None): 113 118 """ 114 119 View that checks the hash in a password reset link and presents a 115 120 form for entering a new password. … … 137 142 else: 138 143 context_instance['validlink'] = False 139 144 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) 142 148 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})) 149 def 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})) 146 153 147 154 def password_change(request, template_name='registration/password_change_form.html', 148 post_change_redirect=None ):155 post_change_redirect=None, extra_context=None): 149 156 if post_change_redirect is None: 150 157 post_change_redirect = reverse('django.contrib.auth.views.password_change_done') 151 158 if request.method == "POST": … … 155 162 return HttpResponseRedirect(post_change_redirect) 156 163 else: 157 164 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)) 161 168 password_change = login_required(password_change) 162 169 163 def password_change_done(request, template_name='registration/password_change_done.html'): 164 return render_to_response(template_name, context_instance=RequestContext(request)) 170 def 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))