Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 spookylukey authored
5 django/contrib/admin/views/main.py
View
@@ -2,6 +2,7 @@
from django.conf import settings
from django.contrib.admin.filterspecs import FilterSpec
from django.contrib.admin.views.decorators import staff_member_required
+from django.views.decorators.cache import never_cache
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied
from django.core.paginator import ObjectPaginator, InvalidPage
@@ -394,7 +395,7 @@ def change_stage(request, app_label, model_name, object_id):
'is_popup': request.REQUEST.has_key('_popup'),
})
return render_change_form(model, manipulator, c, change=True)
-change_stage = staff_member_required(change_stage)
+change_stage = staff_member_required(never_cache(change_stage))
def _nest_help(obj, depth, val):
current = obj
@@ -515,7 +516,7 @@ def delete_stage(request, app_label, model_name, object_id):
return render_to_response(["admin/%s/%s/delete_confirmation" % (app_label, opts.object_name.lower() ),
"admin/%s/delete_confirmation" % app_label ,
"admin/delete_confirmation"], extra_context, context_instance=template.RequestContext(request))
-delete_stage = staff_member_required(delete_stage)
+delete_stage = staff_member_required(never_cache(delete_stage))
def history(request, app_label, model_name, object_id):
model = models.get_model(app_label, model_name)
2  django/utils/cache.py
View
@@ -80,6 +80,8 @@ def patch_response_headers(response, cache_timeout=None):
if not response.has_header('Expires'):
expires = now + datetime.timedelta(0, cache_timeout)
response['Expires'] = expires.strftime('%a, %d %b %Y %H:%M:%S GMT')
+ if cache_timeout < 0:
+ cache_timeout = 0 # Can't have max-age negative
patch_cache_control(response, max_age=cache_timeout)
def patch_vary_headers(response, newheaders):
14 django/views/decorators/cache.py
View
@@ -13,8 +13,9 @@
import re
from django.utils.decorators import decorator_from_middleware
-from django.utils.cache import patch_cache_control
+from django.utils.cache import patch_cache_control, patch_response_headers
from django.middleware.cache import CacheMiddleware
+import datetime
cache_page = decorator_from_middleware(CacheMiddleware)
@@ -31,3 +32,14 @@ def _cache_controlled(request, *args, **kw):
return _cache_controller
+
+def never_cache(view_func):
+ """
+ Decorator that adds headers to a response so that it will
+ never be cached.
+ """
+ def _wrapped_view_func(request, *args, **kwargs):
+ response = view_func(request, *args, **kwargs)
+ patch_response_headers(response, cache_timeout=-1)
+ return response
+ return _wrapped_view_func
Please sign in to comment.
Something went wrong with that request. Please try again.