• 
      

    Properly represent JSON data in text fields in the admin UI.

    Review Request #5082 — Created Dec. 9, 2013 and submitted

    Information

    Djblets
    release-0.7.x

    Reviewers

    Properly represent JSON data in text fields in the admin UI.

    Our JSON support has historically had some issues in the admin UI,
    though we broke it a bit further in a recent release. This change
    finally makes it work the way we always dreamed it would.

    JSON data is now properly shown as-is, not as a Python repr() of the
    structure, complete with validation. What's saved becomes valid JSON in
    the model.

    To make this work, JSONField now uses a custom form field
    (JSONFormField) to do the conversion at the appropriate time from the
    Python data to the serialized JSON. This will automatically be used in
    every part of the admin UI and in every form that uses a JSONField.

    Note that as part of this, I've backed out the previous change intended
    to fix this. It actually regressed the functionality by concealing any
    exceptions raised during JSON validation and turning the whole thing into
    an empty dictionary, which was pretty bad. It also used the new-style
    except Exception as e syntax, breaking Python 2.4 and 2.5.

    Unit tests pass.

    I checked several database entries and saw valid JSON.

    Tried entering invalid JSON and got a useful error message telling me
    what was wrong.

    Entered valid JSON and it saved correctly.

    david
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed