Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #14690: Pretty-format JSON fields in the config form #15623

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
4 checks passed
@markkuleinio markkuleinio deleted the 14690-json-encoder-for-params branch April 22, 2024 14:31
JCWasmx86 pushed a commit to JCWasmx86/netbox that referenced this pull request Apr 23, 2024
…g form (netbox-community#15623)

* Closes netbox-community#14690: Pretty-format JSON fields in the config form

* Revert changes

* Use our own JSONField for config parameters for pretty editor outputs

* Compare identity instead of equality
@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