feat: support pretty printing in tojson filter (#681)#769
Open
SHYXIN wants to merge 3 commits into
Open
Conversation
The custom tojson filter now accepts an optional indent parameter,
enabling pretty printed JSON output in templates. Default behavior
is unchanged (no indent).
Usage in templates:
{{ data|tojson }} # compact (default)
{{ data|tojson(indent=2) }} # pretty printed
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #769 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 86 86
Lines 6848 6848
=========================================
Hits 6848 6848 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The custom
tojsonfilter now accepts an optionalindentparameter, enabling pretty printed JSON output in templates. Default behavior is unchanged.Changes
starlette_admin/base.py:255— Addedindent=Noneparameter to thetojsonfilter lambdaUsage
{{ data|tojson }} # compact (default, backward compatible) {{ data|tojson(indent=2) }} # pretty printed with 2-space indentUsers can override the JSONField display template to use pretty printing:
With a custom template:
Testing
Additional
Includes chore commit to fix pyproject.toml pytest config conflict.