• 
      

    Improve the capabilities of UpdateFormMixin for API resources.

    Review Request #10370 — Created Jan. 2, 2019 and submitted

    Information

    Djblets
    release-1.0.x
    24c7855...

    Reviewers

    UpdateFormMixin was introduced in Djblets 0.9 to make it easier for
    API resources to interface with forms. It offered functionality for
    creating instances of forms and to parse data coming in from the API
    request.

    It was a very useful first step, but left much up to the API resources.
    It required the caller to handle much of the request/response data
    handling, had no official method for parsing methods to validate and
    raise errors, and didn't handle a form's initial data.

    This change offers a whole new set of improvements to this mixin. It
    makes it easier to construct forms from API requests by automatically
    providing all initial field data for the form, so that the caller
    doesn't have to, and it provides official support for gathering and
    returning errors from parsing methods.

    It also wraps much of the existing functionality in some new convenience
    methods. Rather than calling create_form(), API resources can now call
    handle_form_request(). This takes care of calling create_form(),
    checking for form validity, and then returning an error payload or
    saving and returning a success payload.

    Subclasses can override how these payloads are constructed, perform
    additional error payload handling, change how forms are saved, and
    manipulate data before or after creating the form. This also
    automatically works with the new field validation in the parser methods.

    These changes should slim down any resources that use forms
    significantly, and make it much easier to maintain resources in a
    standard way going forward.

    Unit tests pass.

    Used all the new functionality in a resource in Review Board and
    saw the expected behavior.

    Description From Last Updated

    E501 line too long (80 > 79 characters)

    reviewbotreviewbot

    E127 continuation line over-indented for visual indent

    reviewbotreviewbot
    Checks run (1 failed, 1 succeeded)
    flake8 failed.
    JSHint passed.

    flake8

    chipx86
    david
    1. Ship It!
    2. 
        
    chipx86
    david
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-1.0.x (0ad9496)