From a97648a7e03fb95b09e888e5d59d82d57fb289b7 Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Sat, 26 Sep 2009 19:39:42 +0000 Subject: [PATCH] Corrected regressions introduced in r11586 and r11593 I read the order of arguments in the docs incorrectly, doh! git-svn-id: http://code.djangoproject.com/svn/django/trunk@11594 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/views/decorators/cache.py | 16 ++++++++++------ tests/regressiontests/decorators/tests.py | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/django/views/decorators/cache.py b/django/views/decorators/cache.py index 5055104ee2..6e6835ad96 100644 --- a/django/views/decorators/cache.py +++ b/django/views/decorators/cache.py @@ -23,20 +23,24 @@ from django.middleware.cache import CacheMiddleware def cache_page(*args): # We need backwards compatibility with code which spells it this way: # def my_view(): pass - # my_view = cache_page(123, my_view) + # my_view = cache_page(my_view, 123) # and this way: # my_view = cache_page(123)(my_view) + # and possibly this way (?): + # my_view = cache_page(123, my_view) # We also add some asserts to give better error messages in case people are # using other ways to call cache_page that no longer work. - timeout = args[0] if len(args) > 1: assert len(args) == 2, "cache_page accepts at most 2 arguments" - fn = args[1] - assert callable(fn), "cache_page is expecting 2nd argument to be a callable" - return decorator_from_middleware_with_args(CacheMiddleware)(timeout)(fn) + if callable(args[0]): + return decorator_from_middleware_with_args(CacheMiddleware)(args[1])(args[0]) + elif callable(args[1]): + return decorator_from_middleware_with_args(CacheMiddleware)(args[0])(args[1]) + else: + assert False, "cache_page must be passed either a single argument (timeout) or a view function and a timeout" else: - return decorator_from_middleware_with_args(CacheMiddleware)(timeout) + return decorator_from_middleware_with_args(CacheMiddleware)(args[0]) def cache_control(**kwargs): diff --git a/tests/regressiontests/decorators/tests.py b/tests/regressiontests/decorators/tests.py index 8e38ad11ed..64d2d7df73 100644 --- a/tests/regressiontests/decorators/tests.py +++ b/tests/regressiontests/decorators/tests.py @@ -105,7 +105,7 @@ class DecoratorsTest(TestCase): """ def my_view(request): return "response" - my_view_cached = cache_page(123, my_view) + my_view_cached = cache_page(my_view, 123) self.assertEqual(my_view_cached(HttpRequest()), "response") class MethodDecoratorAdapterTests(TestCase):