Ticket #5394: configurable-redirect-field-name.diff

File configurable-redirect-field-name.diff, 3.8 KB (added by Petr Marhoun <petr.marhoun@…>, 17 years ago)
  • django/conf/global_settings.py

    === modified file 'django/conf/global_settings.py'
     
    328328
    329329LOGIN_REDIRECT_URL = '/accounts/profile/'
    330330
     331REDIRECT_FIELD_NAME = 'next'
     332
    331333###########
    332334# TESTING #
    333335###########
  • django/contrib/auth/__init__.py

    === modified file 'django/contrib/auth/__init__.py'
     
    33
    44SESSION_KEY = '_auth_user_id'
    55BACKEND_SESSION_KEY = '_auth_user_backend'
    6 REDIRECT_FIELD_NAME = 'next'
    76
    87def load_backend(path):
    98    i = path.rfind('.')
  • django/contrib/auth/decorators.py

    === modified file 'django/contrib/auth/decorators.py'
     
    1 from django.contrib.auth import REDIRECT_FIELD_NAME
    21from django.http import HttpResponseRedirect
    32from urllib import quote
    43
     
    87    redirecting to the log-in page if necessary. The test should be a callable
    98    that takes the user object and returns True if the user passes.
    109    """
     10    from django.conf import settings
    1111    if not login_url:
    12         from django.conf import settings
    1312        login_url = settings.LOGIN_URL
    1413    def _dec(view_func):
    1514        def _checklogin(request, *args, **kwargs):
    1615            if test_func(request.user):
    1716                return view_func(request, *args, **kwargs)
    18             return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, quote(request.get_full_path())))
     17            return HttpResponseRedirect('%s?%s=%s' % (login_url, settings.REDIRECT_FIELD_NAME, quote(request.get_full_path())))
    1918        _checklogin.__doc__ = view_func.__doc__
    2019        _checklogin.__dict__ = view_func.__dict__
    2120
  • django/contrib/auth/views.py

    === modified file 'django/contrib/auth/views.py'
     
    66from django.contrib.sites.models import Site, RequestSite
    77from django.http import HttpResponseRedirect
    88from django.contrib.auth.decorators import login_required
    9 from django.contrib.auth import REDIRECT_FIELD_NAME
    109from django.utils.translation import ugettext as _
    1110
    1211def login(request, template_name='registration/login.html'):
    1312    "Displays the login form and handles the login action."
    1413    manipulator = AuthenticationForm(request)
    15     redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
     14    from django.conf import settings
     15    redirect_to = request.REQUEST.get(settings.REDIRECT_FIELD_NAME, '')
    1616    if request.POST:
    1717        errors = manipulator.get_validation_errors(request.POST)
    1818        if not errors:
    1919            # Light security check -- make sure redirect_to isn't garbage.
    2020            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
    21                 from django.conf import settings
    2221                redirect_to = settings.LOGIN_REDIRECT_URL
    2322            from django.contrib.auth import login
    2423            login(request, manipulator.get_user())
     
    3534
    3635    return render_to_response(template_name, {
    3736        'form': oldforms.FormWrapper(manipulator, request.POST, errors),
    38         REDIRECT_FIELD_NAME: redirect_to,
     37        settings.REDIRECT_FIELD_NAME: redirect_to,
    3938        'site_name': current_site.name,
    4039    }, context_instance=RequestContext(request))
    4140
     
    6160    if not login_url:
    6261        from django.conf import settings
    6362        login_url = settings.LOGIN_URL
    64     return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, next))
     63    return HttpResponseRedirect('%s?%s=%s' % (login_url, settings.REDIRECT_FIELD_NAME, next))
    6564
    6665def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html',
    6766        email_template_name='registration/password_reset_email.html'):
Back to Top