utf8-friendly dumpdata management command (no escape symbols) #2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# serializers/json_pretty.py
"""
Add the line to settings.py::

    SERIALIZATION_MODULES = {'json-pretty': 'serializers.json_pretty'}

And call dumpdata as follows::

    ./manage.py dumpdata --format=json-pretty <app_name>

"""

import codecs
from django.utils import simplejson
from django.core.serializers.json import Serializer as JSONSerializer
from django.core.serializers.json import Deserializer
from django.core.serializers.json import DjangoJSONEncoder

class Serializer(JSONSerializer):
    def end_serialization(self):
        stream = codecs.getwriter('utf8')(self.stream)
        simplejson.dump(self.objects, stream, cls=DjangoJSONEncoder,
                        ensure_ascii=False, **self.options)

More like this

  1. utf8-friendly dumpdata management command (no escape symbols) #3 by inductor 2 weeks, 3 days ago
  2. utf8-friendly dumpdata management command for yaml (no escape symbols) by mucius 5 days, 10 hours ago
  3. utf8-friendly dumpdata management command (no escape symbols) by dirol 2 years, 6 months ago
  4. dumpdata/loaddata with MySQL and ForeignKeys, as django command by brondsem 4 years, 1 month ago
  5. Generic admin action export selected rows to excel by jordic 1 year, 7 months ago

Comments

(Forgotten your password?)