Ticket #5298: django.contrib.auth.views.patch

File django.contrib.auth.views.patch, 4.5 KB (added by Jj <jjdelc@…>, 16 years ago)

extra_context added to views

  • views.

    old new  
    99from django.contrib.auth import REDIRECT_FIELD_NAME
    1010from django.utils.translation import ugettext as _
    1111
    12 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME):
     12def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME, extra_context={}):
    1313    "Displays the login form and handles the login action."
    1414    manipulator = AuthenticationForm(request)
    1515    redirect_to = request.REQUEST.get(redirect_field_name, '')
     
    3737        'form': oldforms.FormWrapper(manipulator, request.POST, errors),
    3838        redirect_field_name: redirect_to,
    3939        'site_name': current_site.name,
    40     }, context_instance=RequestContext(request))
     40    }, context_instance=RequestContext(request, extra_context))
    4141
    42 def logout(request, next_page=None, template_name='registration/logged_out.html'):
     42def logout(request, next_page=None, template_name='registration/logged_out.html', extra_context={}):
    4343    "Logs out the user and displays 'You are logged out' message."
    4444    from django.contrib.auth import logout
    4545    logout(request)
    4646    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))
    4848    else:
    4949        # Redirect to this page until the session has been cleared.
    5050        return HttpResponseRedirect(next_page or request.path)
    5151
    52 def logout_then_login(request, login_url=None):
     52def logout_then_login(request, login_url=None, extra_context={}):
    5353    "Logs out the user if he is logged in. Then redirects to the log-in page."
    5454    if not login_url:
    5555        from django.conf import settings
    5656        login_url = settings.LOGIN_URL
    57     return logout(request, login_url)
     57
     58    return logout(request, login_url, extra_context=extra_context)
    5859
    5960def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
    6061    "Redirects the user to the login page, passing the given 'next' page"
     
    6465    return HttpResponseRedirect('%s?%s=%s' % (login_url, redirect_field_name, next))
    6566
    6667def 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={}):
    6869    new_data, errors = {}, {}
    6970    form = PasswordResetForm()
    7071    if request.POST:
     
    7677            else:
    7778                form.save(email_template_name=email_template_name)
    7879            return HttpResponseRedirect('%sdone/' % request.path)
     80
    7981    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))
    8183
    82 def password_reset_done(request, template_name='registration/password_reset_done.html'):
    83     return render_to_response(template_name, context_instance=RequestContext(request))
     84def 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))
    8486
    85 def password_change(request, template_name='registration/password_change_form.html'):
     87def password_change(request, template_name='registration/password_change_form.html', extra_context={}):
    8688    new_data, errors = {}, {}
    8789    form = PasswordChangeForm(request.user)
    8890    if request.POST:
     
    9193        if not errors:
    9294            form.save(new_data)
    9395            return HttpResponseRedirect('%sdone/' % request.path)
     96
    9497    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))
    9699password_change = login_required(password_change)
    97100
    98 def password_change_done(request, template_name='registration/password_change_done.html'):
    99     return render_to_response(template_name, context_instance=RequestContext(request))
     101def 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))
Back to Top