Ticket #5298: patch_5298.2.diff
File patch_5298.2.diff, 5.1 KB (added by , 17 years ago) |
---|
-
django/contrib/auth/views.py
1 __all__ = ('login', 'logout', 'logout_then_login', 'redirect_to_login', 2 'password_reset', 'password_reset_done', 'password_change', 3 'password_change_done') 4 1 5 from django.contrib.auth.forms import AuthenticationForm 2 6 from django.contrib.auth.forms import PasswordResetForm, PasswordChangeForm 3 7 from django import oldforms … … 9 13 from django.contrib.auth import REDIRECT_FIELD_NAME 10 14 from django.utils.translation import ugettext as _ 11 15 12 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME): 16 def update_context_from_extra(context, extra_context): 17 if extra_context is None: extra_context = {} 18 for key, value in extra_context.items(): 19 if callable(value): 20 context[key] = value() 21 else: 22 context[key] = value 23 24 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME, extra_context=None): 13 25 "Displays the login form and handles the login action." 14 26 manipulator = AuthenticationForm(request) 15 27 redirect_to = request.REQUEST.get(redirect_field_name, '') … … 33 45 else: 34 46 current_site = RequestSite(request) 35 47 36 return render_to_response(template_name,{48 context = { 37 49 'form': oldforms.FormWrapper(manipulator, request.POST, errors), 38 50 redirect_field_name: redirect_to, 39 51 'site_name': current_site.name, 40 }, context_instance=RequestContext(request)) 52 } 53 update_context_from_extra(context, extra_context) 41 54 42 def logout(request, next_page=None, template_name='registration/logged_out.html'): 55 return render_to_response(template_name, context, 56 context_instance=RequestContext(request)) 57 58 def logout(request, next_page=None, template_name='registration/logged_out.html', extra_context=None): 43 59 "Logs out the user and displays 'You are logged out' message." 44 60 from django.contrib.auth import logout 45 61 logout(request) 46 62 if next_page is None: 47 return render_to_response(template_name, {'title': _('Logged out')}, context_instance=RequestContext(request)) 63 context = {'title': _('Logged out')} 64 update_context_from_extra(context, extra_context) 65 return render_to_response(template_name, context, context_instance=RequestContext(request)) 48 66 else: 49 67 # Redirect to this page until the session has been cleared. 50 68 return HttpResponseRedirect(next_page or request.path) … … 64 82 return HttpResponseRedirect('%s?%s=%s' % (login_url, redirect_field_name, next)) 65 83 66 84 def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html', 67 email_template_name='registration/password_reset_email.html' ):85 email_template_name='registration/password_reset_email.html', extra_context=None): 68 86 new_data, errors = {}, {} 69 87 form = PasswordResetForm() 70 88 if request.POST: … … 76 94 else: 77 95 form.save(email_template_name=email_template_name) 78 96 return HttpResponseRedirect('%sdone/' % request.path) 79 return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)}, 97 context = {'form': oldforms.FormWrapper(form, new_data, errors)} 98 update_context_from_extra(context, extra_context) 99 return render_to_response(template_name, context, 80 100 context_instance=RequestContext(request)) 81 101 82 def password_reset_done(request, template_name='registration/password_reset_done.html'): 83 return render_to_response(template_name, context_instance=RequestContext(request)) 102 def password_reset_done(request, template_name='registration/password_reset_done.html', extra_context=None): 103 context = {} 104 update_context_from_extra(context, extra_context) 105 return render_to_response(template_name, context, context_instance=RequestContext(request)) 84 106 85 def password_change(request, template_name='registration/password_change_form.html' ):107 def password_change(request, template_name='registration/password_change_form.html', extra_context=None): 86 108 new_data, errors = {}, {} 87 109 form = PasswordChangeForm(request.user) 88 110 if request.POST: … … 91 113 if not errors: 92 114 form.save(new_data) 93 115 return HttpResponseRedirect('%sdone/' % request.path) 94 return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)}, 116 context = {'form': oldforms.FormWrapper(form, new_data, errors)} 117 update_context_from_extra(context, extra_context) 118 return render_to_response(template_name, context, 95 119 context_instance=RequestContext(request)) 96 120 password_change = login_required(password_change) 97 121 98 def password_change_done(request, template_name='registration/password_change_done.html' ):122 def password_change_done(request, template_name='registration/password_change_done.html', extra_context=None): 99 123 return render_to_response(template_name, context_instance=RequestContext(request))