Improve the editing experience for JSONFields.

Review Request #9405 — Created Nov. 27, 2017 and submitted — Latest diff uploaded

Information

Djblets
release-1.0.x
0172908...

Reviewers

JSONFormField (through JSONField) had a pretty underwhelming editing
experience when used in forms. The text field would just contain a big
blob of serialized JSON content, which was pretty hard to read and
modify.

Now, the text field shows a pretty-printed representation of the JSON
data, with all keys sorted to make it easier to find the key you want.
When saved, the resulting data is once again condensed, but with the
keys remaining sorted in the database.

In order to do this, the old encoder argument for these classes has
been deprecated, with new encoder_cls and encoder_kwargs replacing
them. This allows the classes to decide when the encoder is constructed
and to provide additional arguments to control the behavior. Any
consumers providing a custom encoder today will not see the new editing
behavior, falling back on the legacy behavior instead.

Manually tested loading a JSON structure and editing it in the Admin UI.
Saw that the data was nicely indented and sorted. Saved it and saw that
the data was condensed in the database, but still sorted.

Unit tests pass.

    Loading...