Django

Code

Ticket #6110: 6110-2.diff

File 6110-2.diff, 4.7 kB (added by empty, 1 year ago)

Never fails. Forgot the new fixture4.python file for the test.

  • django/core/serializers/__init__.py

    old new  
    5353        _load_serializers() 
    5454    return _serializers.keys() 
    5555 
     56def get_public_serializer_formats(): 
     57    return [f for f in get_serializer_formats() if f != 'python'] 
     58 
    5659def get_deserializer(format): 
    5760    if not _serializers: 
    5861        _load_serializers() 
  • django/core/management/commands/dumpdata.py

    old new  
    11from django.core.management.base import BaseCommand, CommandError 
     2from django.core import serializers 
    23 
    34from optparse import make_option 
    45 
    56class Command(BaseCommand): 
     7    serializer_formats = serializers.get_public_serializer_formats() 
    68    option_list = BaseCommand.option_list + ( 
    79        make_option('--format', default='json', dest='format', 
    8             help='Specifies the output serialization format for fixtures'), 
     10            help='Specifies the output serialization format for fixtures.  Formats available: %s' % serializer_formats), 
    911        make_option('--indent', default=None, dest='indent', type='int', 
    1012            help='Specifies the indent level to use when pretty-printing output'), 
    1113    ) 
     
    1416 
    1517    def handle(self, *app_labels, **options): 
    1618        from django.db.models import get_app, get_apps, get_models 
    17         from django.core import serializers 
    1819 
    1920        format = options.get('format', 'json') 
    2021        indent = options.get('indent', None) 
     
    2627 
    2728        # Check that the serialization format exists; this is a shortcut to 
    2829        # avoid collating all the objects and _then_ failing. 
     30        if format not in self.serializer_formats: 
     31            raise CommandError("Unknown serialization format: %s" % format) 
     32         
    2933        try: 
    3034            serializers.get_serializer(format) 
    3135        except KeyError: 
  • django/core/management/commands/loaddata.py

    old new  
    5050            parts = fixture_label.split('.') 
    5151            if len(parts) == 1: 
    5252                fixture_name = fixture_label 
    53                 formats = serializers.get_serializer_formats() 
     53                formats = serializers.get_public_serializer_formats() 
    5454            else: 
    5555                fixture_name, format = '.'.join(parts[:-1]), parts[-1] 
    56                 if format in serializers.get_serializer_formats(): 
     56                if format in serializers.get_public_serializer_formats(): 
    5757                    formats = [format] 
    5858                else: 
    5959                    formats = [] 
  • tests/modeltests/fixtures/fixtures/fixture4.python

    old new  
  • tests/modeltests/fixtures/models.py

    old new  
    5454# object list is unaffected 
    5555>>> Article.objects.all() 
    5656[<Article: XML identified as leading cause of cancer>, <Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker on TV is great!>, <Article: Python program becomes self aware>] 
     57 
     58# Try to dump the current contents of the database in an unsupported format 
     59>>> management.call_command('dumpdata', 'fixtures', format='python', verbosity=0) 
     60Traceback (most recent call last): 
     61  ... 
     62SystemExit: 1 
     63 
     64# Load a fixture that is not in a supported format 
     65>>> management.call_command('loaddata', 'fixture4.python', verbosity=0) 
     66 
     67# object list is unaffected 
     68>>> Article.objects.all() 
     69[<Article: XML identified as leading cause of cancer>, <Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker on TV is great!>, <Article: Python program becomes self aware>] 
    5770"""} 
    5871 
    5972# Database flushing does not work on MySQL with the default storage engine