From 90775067e14ea4017e2702a66b933a1a8365826e Mon Sep 17 00:00:00 2001 From: Bryan Date: Tue, 14 Jan 2014 03:36:29 +0000 Subject: [PATCH] inclusion of json_pretty for dumping with better UTF8 handling --- karmaworld/apps/serializers/__init__.py | 0 karmaworld/apps/serializers/json_pretty.py | 20 ++++++++++++++++++++ karmaworld/settings/common.py | 3 +++ 3 files changed, 23 insertions(+) create mode 100644 karmaworld/apps/serializers/__init__.py create mode 100644 karmaworld/apps/serializers/json_pretty.py diff --git a/karmaworld/apps/serializers/__init__.py b/karmaworld/apps/serializers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/karmaworld/apps/serializers/json_pretty.py b/karmaworld/apps/serializers/json_pretty.py new file mode 100644 index 0000000..5cbe522 --- /dev/null +++ b/karmaworld/apps/serializers/json_pretty.py @@ -0,0 +1,20 @@ +# Snippet from +# https://djangosnippets.org/snippets/2916/ +""" +Add the line to settings.py:: + + SERIALIZATION_MODULES = {'json-pretty': 'serializers.json_pretty'} + +And call dumpdata as follows:: + + ./manage.py dumpdata --format=json-pretty + +""" + +from django.core.serializers.json import Serializer as JSONSerializer + + +class Serializer(JSONSerializer): + def start_serialization(self): + super(Serializer, self).start_serialization() + self.json_kwargs['ensure_ascii'] = False diff --git a/karmaworld/settings/common.py b/karmaworld/settings/common.py index 568f7f6..fea3ae2 100644 --- a/karmaworld/settings/common.py +++ b/karmaworld/settings/common.py @@ -15,6 +15,9 @@ from karmaworld.secret.filepicker import FILEPICKER_API_KEY as fp_api FILEPICKER_API_KEY = fp_api +SERIALIZATION_MODULES = {'json-pretty': 'karmaworld.apps.serializers.json_pretty'} + + ########## REQUIRED SECURITY CONFIGURATION # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-ALLOWED_HOSTS # The hosts that this server runs from. -- 2.25.1