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

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@ttanner
Contributor
ttanner commented Jun 2, 2014

ping

@timgraham timgraham commented on the diff Aug 14, 2014
django/views/decorators/http.py
@@ -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
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
tests/conditional_processing/views.py
-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
timgraham Aug 14, 2014 Member

missing space after comma (check code with flake8)

@timgraham
Member

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

@timgraham
Member

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