diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-05-02 01:31:56 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-05-02 01:31:56 +0000 |
| commit | f69cf70ed813a8cd7e1f963a14ae39103e8d5265 (patch) | |
| tree | d3b32e84cd66573b3833ddf662af020f8ef2f7a8 /django/views/decorators | |
| parent | d5dbeaa9be359a4c794885c2e9f1b5a7e5e51fb8 (diff) | |
MERGED MAGIC-REMOVAL BRANCH TO TRUNK. This change is highly backwards-incompatible. Please read http://code.djangoproject.com/wiki/RemovingTheMagic for upgrade instructions.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2809 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/views/decorators')
| -rw-r--r-- | django/views/decorators/auth.py | 23 | ||||
| -rw-r--r-- | django/views/decorators/cache.py | 12 | ||||
| -rw-r--r-- | django/views/decorators/http.py | 2 |
3 files changed, 12 insertions, 25 deletions
diff --git a/django/views/decorators/auth.py b/django/views/decorators/auth.py deleted file mode 100644 index 478f0ac84d..0000000000 --- a/django/views/decorators/auth.py +++ /dev/null @@ -1,23 +0,0 @@ -from django.views.auth import login - -def user_passes_test(test_func, login_url=login.LOGIN_URL): - """ - Decorator for views that checks that the user passes the given test, - redirecting to the log-in page if necessary. The test should be a callable - that takes the user object and returns True if the user passes. - """ - def _dec(view_func): - def _checklogin(request, *args, **kwargs): - if test_func(request.user): - return view_func(request, *args, **kwargs) - return login.redirect_to_login(request.path, login_url) - return _checklogin - return _dec - -login_required = user_passes_test(lambda u: not u.is_anonymous()) -login_required.__doc__ = ( - """ - Decorator for views that checks that the user is logged in, redirecting - to the log-in page if necessary. - """ - ) diff --git a/django/views/decorators/cache.py b/django/views/decorators/cache.py index f86372cf4e..5467ff501e 100644 --- a/django/views/decorators/cache.py +++ b/django/views/decorators/cache.py @@ -13,7 +13,7 @@ account on caching -- just like the middleware does. import re from django.utils.decorators import decorator_from_middleware -from django.utils.cache import patch_cache_control +from django.utils.cache import patch_cache_control, add_never_cache_headers from django.middleware.cache import CacheMiddleware cache_page = decorator_from_middleware(CacheMiddleware) @@ -31,3 +31,13 @@ def cache_control(**kwargs): return _cache_controller +def never_cache(view_func): + """ + Decorator that adds headers to a response so that it will + never be cached. + """ + def _wrapped_view_func(request, *args, **kwargs): + response = view_func(request, *args, **kwargs) + add_never_cache_headers(response) + return response + return _wrapped_view_func diff --git a/django/views/decorators/http.py b/django/views/decorators/http.py index b9b6bac757..a15e82fcc7 100644 --- a/django/views/decorators/http.py +++ b/django/views/decorators/http.py @@ -4,7 +4,7 @@ Decorators for views based on HTTP headers. from django.utils.decorators import decorator_from_middleware from django.middleware.http import ConditionalGetMiddleware -from django.utils.httpwrappers import HttpResponseForbidden +from django.http import HttpResponseForbidden conditional_page = decorator_from_middleware(ConditionalGetMiddleware) |
