diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
index e1f0d43..ceb9cfc 100644
a
|
b
|
from django.utils.translation import ugettext as _
|
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 expand_callables(dictionary): |
| 18 | result = {} |
| 19 | for key, value in dictionary.items(): |
| 20 | if callable(value): |
| 21 | result[key] = value() |
| 22 | else: |
| 23 | result[key] = value |
| 24 | return result |
| 25 | |
| 26 | def login(request, template_name='registration/login.html', extra_context=None, |
| 27 | redirect_field_name=REDIRECT_FIELD_NAME): |
18 | 28 | "Displays the login form and handles the login action." |
| 29 | if extra_context is None: extra_context = {} |
19 | 30 | redirect_to = request.REQUEST.get(redirect_field_name, '') |
20 | 31 | if request.method == "POST": |
21 | 32 | form = AuthenticationForm(data=request.POST) |
… |
… |
def login(request, template_name='registration/login.html', redirect_field_name=
|
35 | 46 | current_site = Site.objects.get_current() |
36 | 47 | else: |
37 | 48 | current_site = RequestSite(request) |
38 | | return render_to_response(template_name, { |
39 | | 'form': form, |
40 | | redirect_field_name: redirect_to, |
41 | | 'site_name': current_site.name, |
42 | | }, context_instance=RequestContext(request)) |
| 49 | context = {'form': form, |
| 50 | redirect_field_name: redirect_to, 'site_name': current_site.name} |
| 51 | context.update(expand_callables(extra_context)) |
| 52 | return render_to_response(template_name, context, context_instance=RequestContext(request)) |
43 | 53 | login = never_cache(login) |
44 | 54 | |
45 | | def logout(request, next_page=None, template_name='registration/logged_out.html'): |
| 55 | def logout(request, next_page=None, |
| 56 | template_name='registration/logged_out.html', extra_context=None): |
46 | 57 | "Logs out the user and displays 'You are logged out' message." |
| 58 | if extra_context is None: extra_context = {} |
47 | 59 | from django.contrib.auth import logout |
48 | 60 | logout(request) |
49 | 61 | if next_page is None: |
50 | | return render_to_response(template_name, {'title': _('Logged out')}, context_instance=RequestContext(request)) |
| 62 | context = {'title': _('Logged out')} |
| 63 | context.update(expand_callables(extra_context)) |
| 64 | return render_to_response(template_name, context, context_instance=RequestContext(request)) |
51 | 65 | else: |
52 | 66 | # Redirect to this page until the session has been cleared. |
53 | 67 | return HttpResponseRedirect(next_page or request.path) |
… |
… |
def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_N
|
74 | 88 | def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html', |
75 | 89 | email_template_name='registration/password_reset_email.html', |
76 | 90 | password_reset_form=PasswordResetForm, token_generator=default_token_generator, |
77 | | post_reset_redirect=None): |
| 91 | post_reset_redirect=None, extra_context=None): |
78 | 92 | if post_reset_redirect is None: |
79 | 93 | post_reset_redirect = reverse('django.contrib.auth.views.password_reset_done') |
| 94 | if extra_context is None: |
| 95 | extra_context = {} |
80 | 96 | if request.method == "POST": |
81 | 97 | form = password_reset_form(request.POST) |
82 | 98 | if form.is_valid(): |
… |
… |
def password_reset(request, is_admin_site=False, template_name='registration/pas
|
93 | 109 | return HttpResponseRedirect(post_reset_redirect) |
94 | 110 | else: |
95 | 111 | form = password_reset_form() |
96 | | return render_to_response(template_name, { |
97 | | 'form': form, |
98 | | }, context_instance=RequestContext(request)) |
| 112 | context = {'form': form} |
| 113 | context.update(expand_callables(extra_context)) |
| 114 | return render_to_response(template_name, |
| 115 | context, context_instance=RequestContext(request)) |
99 | 116 | |
100 | | def password_reset_done(request, template_name='registration/password_reset_done.html'): |
101 | | return render_to_response(template_name, context_instance=RequestContext(request)) |
| 117 | def password_reset_done(request, |
| 118 | template_name='registration/password_reset_done.html', extra_context=None): |
| 119 | if extra_context is None: |
| 120 | context = {} |
| 121 | else: |
| 122 | context = expand_callables(extra_context) |
| 123 | return render_to_response(template_name, context, context_instance=RequestContext(request)) |
102 | 124 | |
103 | 125 | def password_reset_confirm(request, uidb36=None, token=None, template_name='registration/password_reset_confirm.html', |
104 | 126 | token_generator=default_token_generator, set_password_form=SetPasswordForm, |
105 | | post_reset_redirect=None): |
| 127 | post_reset_redirect=None, extra_context=None): |
106 | 128 | """ |
107 | 129 | View that checks the hash in a password reset link and presents a |
108 | 130 | form for entering a new password. |
… |
… |
def password_reset_confirm(request, uidb36=None, token=None, template_name='regi
|
110 | 132 | assert uidb36 is not None and token is not None # checked by URLconf |
111 | 133 | if post_reset_redirect is None: |
112 | 134 | post_reset_redirect = reverse('django.contrib.auth.views.password_reset_complete') |
| 135 | if extra_context is None: |
| 136 | extra_context = {} |
113 | 137 | try: |
114 | 138 | uid_int = base36_to_int(uidb36) |
115 | 139 | except ValueError: |
… |
… |
def password_reset_confirm(request, uidb36=None, token=None, template_name='regi
|
130 | 154 | else: |
131 | 155 | context_instance['validlink'] = False |
132 | 156 | form = None |
133 | | context_instance['form'] = form |
134 | | return render_to_response(template_name, context_instance=context_instance) |
| 157 | context = {'form': form} |
| 158 | context.update(expand_callables(extra_context)) |
| 159 | return render_to_response(template_name, context, context_instance=context_instance) |
135 | 160 | |
136 | | def password_reset_complete(request, template_name='registration/password_reset_complete.html'): |
137 | | return render_to_response(template_name, context_instance=RequestContext(request, |
138 | | {'login_url': settings.LOGIN_URL})) |
| 161 | def password_reset_complete(request, |
| 162 | template_name='registration/password_reset_complete.html', extra_context=None): |
| 163 | if extra_context is None: extra_context = {} |
| 164 | context = {'login_url': settings.LOGIN_URL} |
| 165 | context.update(expand_callables(extra_context)) |
| 166 | return render_to_response(template_name, context, context_instance=RequestContext(request)) |
139 | 167 | |
140 | 168 | def password_change(request, template_name='registration/password_change_form.html', |
141 | | post_change_redirect=None): |
| 169 | post_change_redirect=None, extra_context=None): |
142 | 170 | if post_change_redirect is None: |
143 | 171 | post_change_redirect = reverse('django.contrib.auth.views.password_change_done') |
| 172 | if extra_context is None: extra_context = {} |
144 | 173 | if request.method == "POST": |
145 | 174 | form = PasswordChangeForm(request.user, request.POST) |
146 | 175 | if form.is_valid(): |
… |
… |
def password_change(request, template_name='registration/password_change_form.ht
|
148 | 177 | return HttpResponseRedirect(post_change_redirect) |
149 | 178 | else: |
150 | 179 | form = PasswordChangeForm(request.user) |
151 | | return render_to_response(template_name, { |
152 | | 'form': form, |
153 | | }, context_instance=RequestContext(request)) |
| 180 | context = {'form': form} |
| 181 | context.update(expand_callables(extra_context)) |
| 182 | return render_to_response(template_name, context, context_instance=RequestContext(request)) |
154 | 183 | password_change = login_required(password_change) |
155 | 184 | |
156 | | def password_change_done(request, template_name='registration/password_change_done.html'): |
157 | | return render_to_response(template_name, context_instance=RequestContext(request)) |
| 185 | def password_change_done(request, template_name='registration/password_change_done.html', |
| 186 | extra_context=None): |
| 187 | if extra_context is None: |
| 188 | context = {} |
| 189 | else: |
| 190 | context = expand_callables(extra_context) |
| 191 | return render_to_response(template_name, context, context_instance=RequestContext(request)) |