Ticket #11927: yaml_dump_style.diff
File yaml_dump_style.diff, 2.8 KB (added by , 14 years ago) |
---|
-
django/core/serializers/pyyaml.py
38 38 super(Serializer, self).handle_field(obj, field) 39 39 40 40 def end_serialization(self): 41 yaml.dump(self.objects, self.stream, Dumper=DjangoSafeDumper, **self.options) 41 yaml.dump(self.objects, self.stream, Dumper=DjangoSafeDumper, 42 default_flow_style=self.options.pop('flowstyle', True), 43 **self.options) 42 44 43 45 def getvalue(self): 44 46 return self.stream.getvalue() … … 53 55 stream = stream_or_string 54 56 for obj in PythonDeserializer(yaml.load(stream), **options): 55 57 yield obj 56 -
django/core/management/commands/dumpdata.py
15 15 make_option('--database', action='store', dest='database', 16 16 default=DEFAULT_DB_ALIAS, help='Nominates a specific database to load ' 17 17 'fixtures into. Defaults to the "default" database.'), 18 make_option('--flowstyle', action='store_true', dest='flowstyle', 19 default=True, help='Uses flow style for YAML data dump.'), 20 make_option('--blockstyle', action='store_false', dest='flowstyle', 21 help='Uses block style for YAML data dump.'), 18 22 make_option('-e', '--exclude', dest='exclude',action='append', default=[], 19 23 help='An appname or appname.ModelName to exclude (use multiple --exclude to exclude multiple apps/models).'), 20 24 make_option('-n', '--natural', action='store_true', dest='use_natural_keys', default=False, … … 32 36 33 37 format = options.get('format','json') 34 38 indent = options.get('indent',None) 39 flowstyle = options.get('flowstyle', True) 35 40 using = options.get('database', DEFAULT_DB_ALIAS) 36 41 connection = connections[using] 37 42 excludes = options.get('exclude',[]) … … 110 115 objects.extend(model._default_manager.using(using).all()) 111 116 112 117 try: 113 return serializers.serialize(format, objects, indent=indent, 114 use_natural_keys=use_natural_keys) 118 opt = { 119 'indent':indent, 120 'use_natural_keys': use_natural_keys, 121 } 122 # This option only makes sense with yaml. 123 if format=='yaml': 124 opt['flowstyle'] = flowstyle 125 return serializers.serialize(format, objects, **opt) 115 126 except Exception, e: 116 127 if show_traceback: 117 128 raise