Ticket #12019: cache_page_default_timeout.diff
File cache_page_default_timeout.diff, 1.8 KB (added by , 14 years ago) |
---|
-
django/views/decorators/cache.py
33 33 # my_view = cache_page(123, key_prefix="foo")(my_view) 34 34 # and possibly this way (?): 35 35 # my_view = cache_page(123, my_view) 36 # and also this way (timeout defaults to CACHE_MIDDLEWARE_SECONDS) 37 # my_view = cache_page(my_view) 36 38 37 39 # We also add some asserts to give better error messages in case people are 38 40 # using other ways to call cache_page that no longer work. … … 46 48 return decorator_from_middleware_with_args(CacheMiddleware)(cache_timeout=args[0], key_prefix=key_prefix)(args[1]) 47 49 else: 48 50 assert False, "cache_page must be passed either a single argument (timeout) or a view function and a timeout" 51 elif callable(args[0]): 52 return decorator_from_middleware_with_args(CacheMiddleware)(key_prefix=key_prefix)(args[0]) 49 53 else: 50 54 return decorator_from_middleware_with_args(CacheMiddleware)(cache_timeout=args[0], key_prefix=key_prefix) 51 55 -
tests/regressiontests/decorators/tests.py
112 112 self.assertEqual(my_view_cached(HttpRequest()), "response") 113 113 my_view_cached2 = cache_page(my_view, 123, key_prefix="test") 114 114 self.assertEqual(my_view_cached2(HttpRequest()), "response") 115 my_view_cached3 = cache_page(my_view) 116 self.assertEqual(my_view_cached3(HttpRequest()), "response") 115 117 116 118 117 119 # For testing method_decorator, a decorator that assumes a single argument.