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
|
| 14 | 14 | redirecting to the log-in page if necessary. The test should be a callable |
| 15 | 15 | that takes the user object and returns True if the user passes. |
| 16 | 16 | """ |
| 17 | | if not login_url: |
| 18 | | from django.conf import settings |
| 19 | | login_url = settings.LOGIN_URL |
| 20 | | |
| 21 | 17 | def decorator(view_func): |
| 22 | 18 | def _wrapped_view(request, *args, **kwargs): |
| 23 | 19 | if test_func(request.user): |
| 24 | 20 | return view_func(request, *args, **kwargs) |
| 25 | 21 | 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)) |
| 28 | 28 | return wraps(view_func)(_wrapped_view) |
| 29 | 29 | return decorator |
| 30 | 30 | |
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index 3bb2c1c..b106470 100644
|
a
|
b
|
from django.conf import settings
|
| 14 | 14 | from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist |
| 15 | 15 | from django.utils.datastructures import MultiValueDict |
| 16 | 16 | from django.utils.encoding import iri_to_uri, force_unicode, smart_str |
| 17 | | from django.utils.functional import memoize |
| | 17 | from django.utils.functional import memoize, lazy |
| 18 | 18 | from django.utils.importlib import import_module |
| 19 | 19 | from django.utils.regex_helper import normalize |
| 20 | 20 | from django.utils.thread_support import currentThread |
| … |
… |
def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current
|
| 355 | 355 | return iri_to_uri(u'%s%s' % (prefix, resolver.reverse(view, |
| 356 | 356 | *args, **kwargs))) |
| 357 | 357 | |
| | 358 | reverse_lazy = lazy(reverse, str) |
| | 359 | |
| 358 | 360 | def clear_url_caches(): |
| 359 | 361 | global _resolver_cache |
| 360 | 362 | global _callable_cache |
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
|
| 824 | 824 | be imported correctly. Do not include lines that reference views you |
| 825 | 825 | haven't written yet, because those views will not be importable. |
| 826 | 826 | |
| | 827 | reverse_lazy() |
| | 828 | -------------- |
| | 829 | |
| | 830 | .. versionadded:: 1.2 |
| | 831 | |
| | 832 | A lazily evaluated version of `reverse()`_. |
| | 833 | |
| | 834 | It is useful for when you need to use a URL reversal before Django's URL names |
| | 835 | map is loaded. Some common cases where this method is necessary are: |
| | 836 | |
| | 837 | * in your URL configuration (such as the ``url`` argument for the |
| | 838 | ``django.views.generic.simple.redirect_to`` generic view). |
| | 839 | |
| | 840 | * providing a reversed URL to a decorator (such as the ``login_url`` argument |
| | 841 | for the ``django.contrib.auth.decorators.permission_required`` decorator). |
| | 842 | |
| 827 | 843 | resolve() |
| 828 | 844 | --------- |
| 829 | 845 | |