chipx86 got a fish trophy!
Add generic view mixins for ETags and finer-grained dispatching.
Review Request #8998 — Created June 5, 2017 and submitted
There are two new mixins added for generic views: One for working with
ETags, and one for more complex views that need to alter dispatch logic.
ETagViewMixin
is a mixin that allows for computing an ETag for a generic
view, checking if the client already has a copy of the content based on
that ETag, and setting appropriate headers in the response. This supports
HTTP GET and HTTP HEAD (but currently no other methods).
PrePostDispatchViewMixin
is useful for views that want to run logic
in the dispatch phase but also make use of mixin that add decorators to
dispatch()
. Since the view'sdispatch()
would run before the ones
decoratored in the mixins, there wasn't a good way to override dispatch
behavior (calculating state, checking access permissions, or augmenting
responses).This mixin solves this by splitting the
dispatch()
method into a
pre_dispatch()
andpost_dispatch()
. When placed after mixins adding
decorators and before mixins alteringdispatch()
logic, views will be
able to get custom logic into the dispatch phase.
pre_dispatch()
can calculate state and optionally return a response to
send directly to the client (useful for access checks).
post_dispatch()
can take a response from the HTTP handler and alter
it. It can even return a custom response, if needed.
Unit tests pass.
Tested manually with some new views I'm writing.
Description | From | Last Updated |
---|---|---|
Module docstring? |
david | |
Module docstring? |
david | |
encode_etag should never return None (since it's doing a sha-1). More likely we should check the truthiness of the result … |
david | |
Module docstring? |
david | |
F401 'django.http.HttpRequest' imported but unused |
reviewbot | |
Module docstring? |
david | |
F401 'django.http.HttpRequest' imported but unused |
reviewbot | |
Why not just use a spy here to ensure the functions are called? |
brennie | |
Missing module-level docstring. |
brennie | |
Missing module-level docstring. |
brennie |