Improve the editing experience for JSONFields.

Review Request #9405 - Created Nov. 27, 2017 and submitted

Christian Hammond
Djblets
release-1.0.x
0172908...
djblets

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.

  • 0
  • 0
  • 3
  • 1
  • 4
Description From Last Updated
David Trowbridge
  1. 
      
  2. djblets/db/fields.py (Diff revision 1)
     
     

    Can we list encoder first to match the JSONField constructor? Or change that one to match this?

  3. djblets/db/fields.py (Diff revision 1)
     
     
     

    We don't actually emit a warning in this method.

  4. djblets/db/fields.py (Diff revision 1)
     
     

    This should probably return self.encoder if it exists.

    1. No need. The property will be overridden in that case.

  5. djblets/db/fields.py (Diff revision 1)
     
     
     

    Too many blank lines.

  6. 
      
Christian Hammond
David Trowbridge
  1. Ship It!
  2. 
      
Christian Hammond
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-1.0.x (a8fc9f9)
Loading...