Ticket #6110: 6110-2.diff
File 6110-2.diff, 4.7 KB (added by , 17 years ago) |
---|
-
django/core/serializers/__init__.py
53 53 _load_serializers() 54 54 return _serializers.keys() 55 55 56 def get_public_serializer_formats(): 57 return [f for f in get_serializer_formats() if f != 'python'] 58 56 59 def get_deserializer(format): 57 60 if not _serializers: 58 61 _load_serializers() -
django/core/management/commands/dumpdata.py
1 1 from django.core.management.base import BaseCommand, CommandError 2 from django.core import serializers 2 3 3 4 from optparse import make_option 4 5 5 6 class Command(BaseCommand): 7 serializer_formats = serializers.get_public_serializer_formats() 6 8 option_list = BaseCommand.option_list + ( 7 9 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), 9 11 make_option('--indent', default=None, dest='indent', type='int', 10 12 help='Specifies the indent level to use when pretty-printing output'), 11 13 ) … … 14 16 15 17 def handle(self, *app_labels, **options): 16 18 from django.db.models import get_app, get_apps, get_models 17 from django.core import serializers18 19 19 20 format = options.get('format', 'json') 20 21 indent = options.get('indent', None) … … 26 27 27 28 # Check that the serialization format exists; this is a shortcut to 28 29 # 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 29 33 try: 30 34 serializers.get_serializer(format) 31 35 except KeyError: -
django/core/management/commands/loaddata.py
50 50 parts = fixture_label.split('.') 51 51 if len(parts) == 1: 52 52 fixture_name = fixture_label 53 formats = serializers.get_ serializer_formats()53 formats = serializers.get_public_serializer_formats() 54 54 else: 55 55 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(): 57 57 formats = [format] 58 58 else: 59 59 formats = [] -
tests/modeltests/fixtures/fixtures/fixture4.python
1 [{'pk': 2, 'model': u'app1.article', 'fields': {'headline': u'Time to reform copyright', 'pub_date': datetime.datetime(2007, 12, 2, 23, 8, 38, 252919)}}, {'pk': 1, 'model': u'app1.article', 'fields': {'headline': u'Poker has no place on ESPN', 'pub_date': datetime.datetime(2007, 12, 2, 23, 8, 4, 651303)}}] -
tests/modeltests/fixtures/models.py
54 54 # object list is unaffected 55 55 >>> Article.objects.all() 56 56 [<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) 60 Traceback (most recent call last): 61 ... 62 SystemExit: 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>] 57 70 """} 58 71 59 72 # Database flushing does not work on MySQL with the default storage engine