Django

Code

Changeset 4661

Show
Ignore:
Timestamp:
03/01/07 20:28:44 (2 years ago)
Author:
russellm
Message:

Added option to pretty-print dumped fixture output

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management.py

    r4659 r4661  
    14141414load_data.args = "[--verbosity] fixture, fixture, ..." 
    14151415  
    1416 def dump_data(app_labels, format='json'): 
     1416def dump_data(app_labels, format='json', indent=None): 
    14171417    "Output the current contents of the database as a fixture of the given format" 
    14181418    from django.db.models import get_app, get_apps, get_models 
     
    14361436            objects.extend(model.objects.all()) 
    14371437    try: 
    1438         print serializers.serialize(format, objects
     1438        print serializers.serialize(format, objects, indent=indent
    14391439    except Exception, e: 
    14401440        sys.stderr.write(style.ERROR("Unable to serialize database: %s\n" % e)) 
     
    15261526    parser.add_option('--format', default='json', dest='format', 
    15271527        help='Specifies the output serialization format for fixtures')     
     1528    parser.add_option('--indent', default=None, dest='indent', 
     1529        type='int', help='Specifies the indent level to use when pretty-printing output') 
    15281530    parser.add_option('--verbosity', action='store', dest='verbosity', default='1', 
    15291531        type='choice', choices=['0', '1', '2'], 
     
    15801582    elif action == 'dumpdata': 
    15811583        try: 
    1582             action_mapping[action](args[1:], options.format
     1584            action_mapping[action](args[1:], options.format, options.indent
    15831585        except IndexError: 
    15841586            parser.print_usage_and_exit() 
  • django/trunk/docs/django-admin.txt

    r4659 r4661  
    474474 
    475475--format 
    476 --------- 
     476-------- 
    477477 
    478478**New in Django development version** 
     
    490490Displays a help message that includes a terse list of all available actions and 
    491491options. 
     492 
     493--indent 
     494-------- 
     495 
     496**New in Django development version** 
     497 
     498Example usage:: 
     499 
     500    django-admin.py dumpdata --indent=4 
     501 
     502Specifies the number of spaces that will be used for indentation when  
     503pretty-printing output. By default, output will *not* be pretty-printed. 
     504Pretty-printing will only be enabled if the indent option is provided. 
    492505 
    493506--noinput