#22461 condition decorator: support for if-unmodified-since and updating etags #2573

wants to merge 1 commit into


None yet

2 participants

ttanner commented Jun 2, 2014


@timgraham timgraham commented on the diff Aug 14, 2014
@@ -52,7 +52,7 @@ def inner(request, *args, **kwargs):
require_safe.__doc__ = "Decorator to require that a view only accept safe methods: GET and HEAD."
-def condition(etag_func=None, last_modified_func=None):
+def condition(etag_func=None, last_modified_func=None, update=("PATCH", "PUT")):
timgraham Aug 14, 2014 Member

This needs documentation updates in docs/topics/http/decorators.txt and topics/conditional-view-processing.txt.

@timgraham timgraham commented on the diff Aug 14, 2014
-def index(request):
- return HttpResponse(FULL_RESPONSE)
-index = condition(lambda r: ETAG, lambda r: LAST_MODIFIED)(index)
+def etag_func(request):
+ return EXPIRED_ETAG if getattr(request,'modified',False) else ETAG
+def index_func(request):
+ request.modified = request.method == 'PUT'
+ return HttpResponse(MODIFIED_RESPONSE if request.modified else FULL_RESPONSE)
+index = condition(etag_func, last_modified_func)(index_func)
+index_static = condition(etag_func, last_modified_func,update=())(index_func)
timgraham Aug 14, 2014 Member

missing space after comma (check code with flake8)


Please rebase so this merges cleanly and see also our patch review checklist for some helpful tips.


Closing due to lack of follow-up, please send a new PR if you can update it, thanks!

@timgraham timgraham closed this Oct 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment