Ticket #11416: 11416-admin-caching.diff

File 11416-admin-caching.diff, 2.3 KB (added by Michael Newman, 15 years ago)

Patch with a test to ensure there is a max-age on the response from the admin

  • django/contrib/admin/options.py

     
    2020from django.utils.translation import ugettext as _
    2121from django.utils.translation import ungettext, ugettext_lazy
    2222from django.utils.encoding import force_unicode
     23from django.views.decorators.cache import never_cache
    2324try:
    2425    set
    2526except NameError:
     
    224225        def wrap(view):
    225226            def wrapper(*args, **kwargs):
    226227                return self.admin_site.admin_view(view)(*args, **kwargs)
    227             return update_wrapper(wrapper, view)
     228            return never_cache(update_wrapper(wrapper, view))
    228229
    229230        info = self.admin_site.name, self.model._meta.app_label, self.model._meta.module_name
    230231
  • django/contrib/admin/sites.py

     
    190190        def wrap(view):
    191191            def wrapper(*args, **kwargs):
    192192                return self.admin_view(view)(*args, **kwargs)
    193             return update_wrapper(wrapper, view)
     193            return never_cache(update_wrapper(wrapper, view))
    194194
    195195        # Admin-site-wide views.
    196196        urlpatterns = patterns('',
  • tests/regressiontests/admin_views/tests.py

     
    5252        """
    5353        response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit)
    5454        self.failUnlessEqual(response.status_code, 200)
     55   
     56    def testMaxAge(self):
     57        """
     58        Because cache time can be set by middleware, ensure max-age is explicity 0
     59        """
     60        response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit)
     61       
     62        from django.utils.cache import get_max_age
     63        self.failUnlessEqual(get_max_age(response), 0)
    5564
    5665    def testAddWithGETArgs(self):
    5766        response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit, {'name': 'My Section'})
Back to Top