Ticket #5925: 5925.diff

File 5925.diff, 3.2 KB (added by Chris Beaven, 14 years ago)
  • django/contrib/auth/decorators.py

    diff --git a/django/contrib/auth/decorators.py b/django/contrib/auth/decorators.py
    index 97db3bb..b815c2b 100644
    a b def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIE  
    1414    redirecting to the log-in page if necessary. The test should be a callable
    1515    that takes the user object and returns True if the user passes.
    1616    """
    17     if not login_url:
    18         from django.conf import settings
    19         login_url = settings.LOGIN_URL
    2117    def decorator(view_func):
    2218        def _wrapped_view(request, *args, **kwargs):
    2319            if test_func(request.user):
    2420                return view_func(request, *args, **kwargs)
    2521            path = urlquote(request.get_full_path())
    26             tup = login_url, redirect_field_name, path
    27             return HttpResponseRedirect('%s?%s=%s' % tup)
     22            url = login_url
     23            if not url:
     24                from django.conf import settings
     25                url = settings.LOGIN_URL
     26            return HttpResponseRedirect('%s?%s=%s' % (url, redirect_field_name,
     27                                                      path))
    2828        return wraps(view_func)(_wrapped_view)
    2929    return decorator
  • django/core/urlresolvers.py

    diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
    index 3bb2c1c..b106470 100644
    a b from django.conf import settings  
    1414from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
    1515from django.utils.datastructures import MultiValueDict
    1616from django.utils.encoding import iri_to_uri, force_unicode, smart_str
    17 from django.utils.functional import memoize
     17from django.utils.functional import memoize, lazy
    1818from django.utils.importlib import import_module
    1919from django.utils.regex_helper import normalize
    2020from django.utils.thread_support import currentThread
    def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current  
    355355    return iri_to_uri(u'%s%s' % (prefix, resolver.reverse(view,
    356356            *args, **kwargs)))
     358reverse_lazy = lazy(reverse, str)
    358360def clear_url_caches():
    359361    global _resolver_cache
    360362    global _callable_cache
  • docs/topics/http/urls.txt

    diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt
    index 0a5d04c..9baa911 100644
    a b namespaces into URLs on specific application instances, according to the  
    824824    be imported correctly. Do not include lines that reference views you
    825825    haven't written yet, because those views will not be importable.
     830.. versionadded:: 1.2
     832A lazily evaluated version of `reverse()`_.
     834It is useful for when you need to use a URL reversal before Django's URL names
     835map is loaded. Some common cases where this method is necessary are:
     837* in your URL configuration (such as the ``url`` argument for the
     838  ``django.views.generic.simple.redirect_to`` generic view).
     840* providing a reversed URL to a decorator (such as the ``login_url`` argument
     841  for the ``django.contrib.auth.decorators.permission_required`` decorator).
Back to Top