Skip to content

Conversation

@markkuleinio
Copy link
Contributor

@markkuleinio markkuleinio commented Apr 4, 2024

Fixes: #14690

Adds encoder attribute in ConfigParam that is set to a custom JSON encoder if field is a JSONField.

Replaces the Django-original JSONField params with our own JSONFields, to get pretty JSON printing in the configuration editor.

@jeremystretch
Copy link
Member

We actually have a custom JSONField class that we use elsewhere to effect cleaner rendering, so ideally we'd reuse that for the relevant config parameters. However, importing the class directly raises an AppRegistryNotReady exception, because the class needs to be imported before the utilities app can be registered.

One option would be to swap out the field class in ConfigFormMetaclass.__new__(), changing param.field to our custom JSON field wherever it's set to Django's stock JSONField. It's a bit of a hack, but IMO reasonably clean given the constraints.

@markkuleinio
Copy link
Contributor Author

I needed to chew this a while 😁 Totally missed the custom JSONField earlier. Let's try again

@jeremystretch
Copy link
Member

Thanks @markkuleinio!

@jeremystretch jeremystretch merged commit b6e38b2 into netbox-community:develop Apr 22, 2024
@markkuleinio markkuleinio deleted the 14690-json-encoder-for-params branch April 22, 2024 14:31
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Format default user preferences (and other) JSON when populating the config editor

2 participants