Commit d6c22867 authored by Luke Plant's avatar Luke Plant
Browse files

Improved error messages when people use cache_page in undocumented and now unsupported ways.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@11593 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 4a2a0b0e
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -20,15 +20,20 @@ from django.utils.decorators import decorator_from_middleware_with_args, auto_ad
from django.utils.cache import patch_cache_control, add_never_cache_headers
from django.middleware.cache import CacheMiddleware

def cache_page(*args, **kwargs):
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)
    # and 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)
    else:
        return decorator_from_middleware_with_args(CacheMiddleware)(timeout)