Author: lukeplant
Date: 2009-09-23 18:47:53 -0500 (Wed, 23 Sep 2009)
New Revision: 11593

Modified:
   django/trunk/django/views/decorators/cache.py
Log:
Improved error messages when people use cache_page in undocumented and now 
unsupported ways.


Modified: django/trunk/django/views/decorators/cache.py
===================================================================
--- django/trunk/django/views/decorators/cache.py       2009-09-23 23:41:35 UTC 
(rev 11592)
+++ django/trunk/django/views/decorators/cache.py       2009-09-23 23:47:53 UTC 
(rev 11593)
@@ -20,15 +20,20 @@
 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)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to