From e7ff9ee6199dec2538c350896174696299e59db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 23 Mar 2017 22:51:36 +0100 Subject: [PATCH] Use compact separators to dump json issue6373 review33991002 --- trytond/ir/model.py | 3 ++- trytond/ir/ui/view.py | 4 ++-- trytond/model/dictschema.py | 2 +- trytond/model/fields/dict.py | 2 +- trytond/protocols/jsonrpc.py | 3 ++- trytond/wizard/wizard.py | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/trytond/ir/model.py b/trytond/ir/model.py index 4e8ea6f24d..c43e1afa7a 100644 --- a/trytond/ir/model.py +++ b/trytond/ir/model.py @@ -1115,7 +1115,8 @@ class ModelData(ModelSQL, ModelView): @classmethod def dump_values(cls, values): - return json.dumps(sorted(values.iteritems()), cls=JSONEncoder) + return json.dumps( + sorted(values.iteritems()), cls=JSONEncoder, separators=(',', ':')) @classmethod def load_values(cls, values): diff --git a/trytond/ir/ui/view.py b/trytond/ir/ui/view.py index 5305b367e4..23324ca3a7 100644 --- a/trytond/ir/ui/view.py +++ b/trytond/ir/ui/view.py @@ -357,7 +357,7 @@ class ViewTreeState(ModelSQL, ModelView): @classmethod def set(cls, model, domain, child_name, nodes, selected_nodes): # Normalize the json domain - domain = json.dumps(json.loads(domain)) + domain = json.dumps(json.loads(domain), separators=(',', ':')) current_user = Transaction().user records = cls.search([ ('user', '=', current_user), @@ -378,7 +378,7 @@ class ViewTreeState(ModelSQL, ModelView): @classmethod def get(cls, model, domain, child_name): # Normalize the json domain - domain = json.dumps(json.loads(domain)) + domain = json.dumps(json.loads(domain), separators=(',', ':')) current_user = Transaction().user try: expanded_info, = cls.search([ diff --git a/trytond/model/dictschema.py b/trytond/model/dictschema.py index 38ed0f5feb..16fc34f36d 100644 --- a/trytond/model/dictschema.py +++ b/trytond/model/dictschema.py @@ -60,7 +60,7 @@ class DictSchemaMixin(object): db_selection = self.selection or '' selection = [[w.strip() for w in v.split(':', 1)] for v in db_selection.splitlines() if v] - return json.dumps(selection) + return json.dumps(selection, separators=(',', ':')) @classmethod def get_keys(cls, records): diff --git a/trytond/model/fields/dict.py b/trytond/model/fields/dict.py index 1f218078eb..414587aa14 100644 --- a/trytond/model/fields/dict.py +++ b/trytond/model/fields/dict.py @@ -37,7 +37,7 @@ class Dict(Field): if value is None: return None assert isinstance(value, dict) - return json.dumps(value, cls=JSONEncoder) + return json.dumps(value, cls=JSONEncoder, separators=(',', ':')) def sql_type(self): return SQLType('TEXT', 'TEXT') diff --git a/trytond/protocols/jsonrpc.py b/trytond/protocols/jsonrpc.py index d415da9668..fd166fa9e9 100644 --- a/trytond/protocols/jsonrpc.py +++ b/trytond/protocols/jsonrpc.py @@ -156,5 +156,6 @@ class JSONProtocol: if isinstance(data, Exception): return InternalServerError(data) response = data - return Response(json.dumps(response, cls=JSONEncoder), + return Response(json.dumps( + response, cls=JSONEncoder, separators=(',', ':')), content_type='application/json') diff --git a/trytond/wizard/wizard.py b/trytond/wizard/wizard.py index f1d2abed1c..48e1b6ad20 100644 --- a/trytond/wizard/wizard.py +++ b/trytond/wizard/wizard.py @@ -341,7 +341,7 @@ class Wizard(WarningErrorMixin, URLMixin, PoolBase): if isinstance(state, StateView): data[state_name] = getattr(self, state_name)._default_values session = Session(self._session_id) - data = json.dumps(data, cls=JSONEncoder) + data = json.dumps(data, cls=JSONEncoder, separators=(',', ':')) if data != session.data.encode('utf-8'): Session.write([session], { 'data': data,