jp (forums/edit): fixed unicode when dumping in json

This commit is contained in:
Goffi 2018-06-03 18:05:01 +02:00
commit 38597f81cf

View file

@ -24,6 +24,7 @@ from sat_frontends.jp.constants import Const as C
from sat_frontends.jp import common
from sat.tools.common.ansi import ANSI as A
from functools import partial
import codecs
import json
__commands__ = ["Forums"]
@ -69,7 +70,9 @@ class Edit(base.CommandBase, common.BaseEdit):
if forums_json:
# we loads and dumps to have pretty printed json
forums = json.loads(forums_json)
json.dump(forums, content_file_obj, ensure_ascii=False, indent=4)
# cf. https://stackoverflow.com/a/18337754
f = codecs.getwriter('utf-8')(content_file_obj)
json.dump(forums, f, ensure_ascii=False, indent=4)
content_file_obj.seek(0)
self.runEditor("forums_editor_args", content_file_path, content_file_obj)