瀏覽代碼

PR570 [core] Update JsonResponse to support set json_dumps_params (#570)

https://github.com/cloudera/hue/pull/570

*  bugfix: common_notebook_ko_components.mako does not import logging

*  update JsonResponse: support set json_dumps_params

*  django_util.py JsonResponse add comment for param json_dumps_params
todaychi 8 年之前
父節點
當前提交
39bc59b
共有 2 個文件被更改,包括 7 次插入3 次删除
  1. 6 2
      desktop/core/src/desktop/lib/django_util.py
  2. 1 1
      desktop/core/src/desktop/lib/metrics/views.py

+ 6 - 2
desktop/core/src/desktop/lib/django_util.py

@@ -466,12 +466,16 @@ class JsonResponse(HttpResponse):
       ``django.core.serializers.json.DjangoJSONEncoder``.
     :param safe: Controls if only ``dict`` objects may be serialized. Defaults
       to ``True``.
+    :param json_dumps_params: A dictionary of kwargs passed to json.dumps().
     """
 
-    def __init__(self, data, encoder=DjangoJSONEncoder, safe=True, indent=None, **kwargs):
+    def __init__(self, data, encoder=DjangoJSONEncoder, safe=True,
+                 json_dumps_params=None, **kwargs):
         if safe and not isinstance(data, dict):
             raise TypeError('In order to allow non-dict objects to be '
                 'serialized set the safe parameter to False')
+        if json_dumps_params is None:
+            json_dumps_params = {}
         kwargs.setdefault('content_type', 'application/json')
-        data = json.dumps(data, cls=encoder, indent=indent)
+        data = json.dumps(data, cls=encoder, **json_dumps_params)
         super(JsonResponse, self).__init__(content=data, **kwargs)

+ 1 - 1
desktop/core/src/desktop/lib/metrics/views.py

@@ -35,4 +35,4 @@ def index(request):
       'timestamp': datetime.datetime.utcnow().isoformat(),
       'metric': global_registry().dump_metrics(),
   }
-  return JsonResponse(rep, indent=indent)
+  return JsonResponse(rep, json_dumps_params={'indent': indent})