Skip to content
Snippets Groups Projects
Verified Commit 3f91f2ac authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Implement JSON pretty-printing

parent 97870e4f
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,12 @@ class IconifyJSONView(View):
if format_ == "js":
callback = request.GET.get("callback", "SimpleSVG._loaderCallback")
# Client can request pretty-printing of JSON
if request.GET.get("pretty", "0").lower() in ("1", "true"):
indent = 2
else:
indent = None
# Load icon set through Iconify types
collection_file = os.path.join(JSON_ROOT, "json", f"{collection}.json")
try:
......@@ -49,7 +55,7 @@ class IconifyJSONView(View):
raise Http404(f"Icon collection {collection} not found") from exc
# Get result JSON and form response
res = json.dumps(icon_set.as_dict())
res = json.dumps(icon_set.as_dict(), indent=indent, sort_keys=True)
if format_ == "js":
res = f"{callback}({res})"
return HttpResponse(res, content_type="application/javascript")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment