Ticket #11927: yaml_dump_style.diff

File yaml_dump_style.diff, 2.8 KB (added by Aviral Dasgupta, 13 years ago)
  • django/core/serializers/pyyaml.py

     
    3838            super(Serializer, self).handle_field(obj, field)
    3939
    4040    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)
    4244
    4345    def getvalue(self):
    4446        return self.stream.getvalue()
     
    5355        stream = stream_or_string
    5456    for obj in PythonDeserializer(yaml.load(stream), **options):
    5557        yield obj
    56 
  • django/core/management/commands/dumpdata.py

     
    1515        make_option('--database', action='store', dest='database',
    1616            default=DEFAULT_DB_ALIAS, help='Nominates a specific database to load '
    1717                '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.'),
    1822        make_option('-e', '--exclude', dest='exclude',action='append', default=[],
    1923            help='An appname or appname.ModelName to exclude (use multiple --exclude to exclude multiple apps/models).'),
    2024        make_option('-n', '--natural', action='store_true', dest='use_natural_keys', default=False,
     
    3236
    3337        format = options.get('format','json')
    3438        indent = options.get('indent',None)
     39        flowstyle = options.get('flowstyle', True)
    3540        using = options.get('database', DEFAULT_DB_ALIAS)
    3641        connection = connections[using]
    3742        excludes = options.get('exclude',[])
     
    110115                    objects.extend(model._default_manager.using(using).all())
    111116
    112117        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)
    115126        except Exception, e:
    116127            if show_traceback:
    117128                raise
Back to Top