• 
      
    Fish Trophy

    chipx86 got a fish trophy!

    Fish Trophy

    Add generic view mixins for ETags and finer-grained dispatching.

    Review Request #8998 — Created June 5, 2017 and submitted — Latest diff uploaded

    Information

    Djblets
    release-0.10.x
    6df4df5...

    Reviewers

    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's dispatch() 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() and post_dispatch(). When placed after mixins adding
    decorators and before mixins altering dispatch() 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.