BryanDavis has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/370135 )

Change subject: Encode toolinfo.json as utf8
......................................................................


Encode toolinfo.json as utf8

Ensure that the generated json content is utf8 encoded. Also add
a charset hint to the Content-type header so that dumb browsers that are
not correctly assuming utf8 encoding for application/json render things
correctly.

Change-Id: I6cb565317e8254180164a27e79f070bb48ffdb17
---
M striker/tools/views/toolinfo.py
1 file changed, 6 insertions(+), 11 deletions(-)

Approvals:
  BryanDavis: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/striker/tools/views/toolinfo.py b/striker/tools/views/toolinfo.py
index 375c68f..def005a 100644
--- a/striker/tools/views/toolinfo.py
+++ b/striker/tools/views/toolinfo.py
@@ -27,7 +27,7 @@
 from django.core.serializers.json import DjangoJSONEncoder
 from django.db import transaction
 from django.db.utils import DatabaseError
-from django.http import JsonResponse
+from django.http import HttpResponse
 from django.utils.text import slugify
 from django.utils.translation import ugettext_lazy as _
 
@@ -324,17 +324,12 @@
 
 
 def json_v1(req):
-    class PrettyPrintJSONEncoder(DjangoJSONEncoder):
-        def __init__(self, *args, **kwargs):
-            kwargs['indent'] = 2
-            kwargs['separators'] = (',', ':')
-            super(PrettyPrintJSONEncoder, self).__init__(*args, **kwargs)
-
-    return JsonResponse(
+    enc = DjangoJSONEncoder(
+        ensure_ascii=False, indent=2, separators=(',', ':'))
+    return HttpResponse(enc.encode(
         [
             info.toolinfo()
             for info in ToolInfo.objects.all().order_by('name')
-        ],
-        encoder=PrettyPrintJSONEncoder,
-        safe=False,
+        ]),
+        content_type="application/json; charset=utf8"
     )

-- 
To view, visit https://gerrit.wikimedia.org/r/370135
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6cb565317e8254180164a27e79f070bb48ffdb17
Gerrit-PatchSet: 3
Gerrit-Project: labs/striker
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <bda...@wikimedia.org>
Gerrit-Reviewer: BryanDavis <bda...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to