Ticket #5298: django.contrib.auth.views.patch
File django.contrib.auth.views.patch, 4.5 KB (added by , 16 years ago) |
---|
-
views.
old new 9 9 from django.contrib.auth import REDIRECT_FIELD_NAME 10 10 from django.utils.translation import ugettext as _ 11 11 12 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME ):12 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME, extra_context={}): 13 13 "Displays the login form and handles the login action." 14 14 manipulator = AuthenticationForm(request) 15 15 redirect_to = request.REQUEST.get(redirect_field_name, '') … … 37 37 'form': oldforms.FormWrapper(manipulator, request.POST, errors), 38 38 redirect_field_name: redirect_to, 39 39 'site_name': current_site.name, 40 }, context_instance=RequestContext(request ))40 }, context_instance=RequestContext(request, extra_context)) 41 41 42 def logout(request, next_page=None, template_name='registration/logged_out.html' ):42 def logout(request, next_page=None, template_name='registration/logged_out.html', extra_context={}): 43 43 "Logs out the user and displays 'You are logged out' message." 44 44 from django.contrib.auth import logout 45 45 logout(request) 46 46 if next_page is None: 47 return render_to_response(template_name, {'title': _('Logged out')}, context_instance=RequestContext(request ))47 return render_to_response(template_name, {'title': _('Logged out')}, context_instance=RequestContext(request, extra_context)) 48 48 else: 49 49 # Redirect to this page until the session has been cleared. 50 50 return HttpResponseRedirect(next_page or request.path) 51 51 52 def logout_then_login(request, login_url=None ):52 def logout_then_login(request, login_url=None, extra_context={}): 53 53 "Logs out the user if he is logged in. Then redirects to the log-in page." 54 54 if not login_url: 55 55 from django.conf import settings 56 56 login_url = settings.LOGIN_URL 57 return logout(request, login_url) 57 58 return logout(request, login_url, extra_context=extra_context) 58 59 59 60 def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): 60 61 "Redirects the user to the login page, passing the given 'next' page" … … 64 65 return HttpResponseRedirect('%s?%s=%s' % (login_url, redirect_field_name, next)) 65 66 66 67 def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html', 67 email_template_name='registration/password_reset_email.html' ):68 email_template_name='registration/password_reset_email.html', extra_context={}): 68 69 new_data, errors = {}, {} 69 70 form = PasswordResetForm() 70 71 if request.POST: … … 76 77 else: 77 78 form.save(email_template_name=email_template_name) 78 79 return HttpResponseRedirect('%sdone/' % request.path) 80 79 81 return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)}, 80 context_instance=RequestContext(request ))82 context_instance=RequestContext(request, extra_context)) 81 83 82 def password_reset_done(request, template_name='registration/password_reset_done.html' ):83 return render_to_response(template_name, context_instance=RequestContext(request ))84 def password_reset_done(request, template_name='registration/password_reset_done.html', extra_context={}): 85 return render_to_response(template_name, context_instance=RequestContext(request, extra_context)) 84 86 85 def password_change(request, template_name='registration/password_change_form.html' ):87 def password_change(request, template_name='registration/password_change_form.html', extra_context={}): 86 88 new_data, errors = {}, {} 87 89 form = PasswordChangeForm(request.user) 88 90 if request.POST: … … 91 93 if not errors: 92 94 form.save(new_data) 93 95 return HttpResponseRedirect('%sdone/' % request.path) 96 94 97 return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)}, 95 context_instance=RequestContext(request ))98 context_instance=RequestContext(request, extra_context)) 96 99 password_change = login_required(password_change) 97 100 98 def password_change_done(request, template_name='registration/password_change_done.html' ):99 return render_to_response(template_name, context_instance=RequestContext(request ))101 def password_change_done(request, template_name='registration/password_change_done.html', extra_context={}): 102 return render_to_response(template_name, context_instance=RequestContext(request, extra_context))