Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

magic-removal: Added 'never_cache' decorator that sets

'Expires' as a past date and max-age=0, and used it in the 
admin to prevent loss of data in the change_stage view.


git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2599 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9db4a5e5ed474376571379b8748c5af313dd4ea6 1 parent d4a6375
Luke Plant authored March 30, 2006
5  django/contrib/admin/views/main.py
@@ -2,6 +2,7 @@
2 2
 from django.conf import settings
3 3
 from django.contrib.admin.filterspecs import FilterSpec
4 4
 from django.contrib.admin.views.decorators import staff_member_required
  5
+from django.views.decorators.cache import never_cache
5 6
 from django.contrib.contenttypes.models import ContentType
6 7
 from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied
7 8
 from django.core.paginator import ObjectPaginator, InvalidPage
@@ -394,7 +395,7 @@ def change_stage(request, app_label, model_name, object_id):
394 395
         'is_popup': request.REQUEST.has_key('_popup'),
395 396
     })
396 397
     return render_change_form(model, manipulator, c, change=True)
397  
-change_stage = staff_member_required(change_stage)
  398
+change_stage = staff_member_required(never_cache(change_stage))
398 399
 
399 400
 def _nest_help(obj, depth, val):
400 401
     current = obj
@@ -515,7 +516,7 @@ def delete_stage(request, app_label, model_name, object_id):
515 516
     return render_to_response(["admin/%s/%s/delete_confirmation" % (app_label, opts.object_name.lower() ),
516 517
                                "admin/%s/delete_confirmation" % app_label ,
517 518
                                "admin/delete_confirmation"], extra_context, context_instance=template.RequestContext(request))
518  
-delete_stage = staff_member_required(delete_stage)
  519
+delete_stage = staff_member_required(never_cache(delete_stage))
519 520
 
520 521
 def history(request, app_label, model_name, object_id):
521 522
     model = models.get_model(app_label, model_name)
2  django/utils/cache.py
@@ -80,6 +80,8 @@ def patch_response_headers(response, cache_timeout=None):
80 80
     if not response.has_header('Expires'):
81 81
         expires = now + datetime.timedelta(0, cache_timeout)
82 82
         response['Expires'] = expires.strftime('%a, %d %b %Y %H:%M:%S GMT')
  83
+    if cache_timeout < 0:
  84
+        cache_timeout = 0 # Can't have max-age negative
83 85
     patch_cache_control(response, max_age=cache_timeout)
84 86
 
85 87
 def patch_vary_headers(response, newheaders):
14  django/views/decorators/cache.py
@@ -13,8 +13,9 @@
13 13
 import re
14 14
 
15 15
 from django.utils.decorators import decorator_from_middleware
16  
-from django.utils.cache import patch_cache_control
  16
+from django.utils.cache import patch_cache_control, patch_response_headers
17 17
 from django.middleware.cache import CacheMiddleware
  18
+import datetime
18 19
 
19 20
 cache_page = decorator_from_middleware(CacheMiddleware)
20 21
 
@@ -31,3 +32,14 @@ def _cache_controlled(request, *args, **kw):
31 32
 
32 33
     return _cache_controller
33 34
 
  35
+
  36
+def never_cache(view_func):
  37
+    """
  38
+    Decorator that adds headers to a response so that it will
  39
+    never be cached.
  40
+    """
  41
+    def _wrapped_view_func(request, *args, **kwargs):
  42
+        response = view_func(request, *args, **kwargs)
  43
+        patch_response_headers(response, cache_timeout=-1)
  44
+        return response
  45
+    return _wrapped_view_func

0 notes on commit 9db4a5e

Please sign in to comment.
Something went wrong with that request. Please try again.