1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #!/usr/bin/env python
from optparse import make_option
from django.core.management.commands.dumpdata import Command as Dumpdata
class Command(Dumpdata):
option_list = Dumpdata.option_list + (
make_option('--pretty', default=False, action='store_true',
dest='pretty', help='Avoid unicode escape symbols'
),
)
def handle(self, *args, **kwargs):
data = super(Command, self).handle(*args, **kwargs)
if kwargs.get('pretty'):
data = data.decode("unicode_escape").encode("utf8")
return data
|
More like this
- streaming serializer by kcarnold 4 years, 1 month ago
- utf8-friendly dumpdata management command for yaml (no escape symbols) by mucius 5 days, 13 hours ago
- utf8-friendly dumpdata management command (no escape symbols) #2 by kmike 2 years, 2 months ago
- utf8-friendly dumpdata management command (no escape symbols) #3 by inductor 2 weeks, 3 days ago
- syncdata command by graham 4 years, 9 months ago
Comments
Is this safe and standards compliant? Why would the Django core devs not have done it the same way?
#
I don't know whether it is safe or not, but fixture generated by this command: 1. Are easy-editable 2. Successfully loads back to database with
./manage.py loaddata.The rest i leave to you )
#
And oh, I only tested json fixtures. I have no idea if it works fine with yaml, and I'm pretty sure It's useless with xml (cause xml fixtures are already fine)
#
This command breaks on e.g. quotes in data because special chars have to be escaped unlike other characters.
From RFC:
#
Another implementation: http://djangosnippets.org/snippets/2397/
#