Fixed #6110 -- Mark the python format serializer as for internal use only. Thanks, empty.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6922 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
6754be48ec
commit
fc413b8f61
|
@ -1,11 +1,13 @@
|
|||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.core import serializers
|
||||
|
||||
from optparse import make_option
|
||||
|
||||
class Command(BaseCommand):
|
||||
serializer_formats = serializers.get_public_serializer_formats()
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--format', default='json', dest='format',
|
||||
help='Specifies the output serialization format for fixtures'),
|
||||
help='Specifies the output serialization format for fixtures. Formats available: %s' % serializer_formats),
|
||||
make_option('--indent', default=None, dest='indent', type='int',
|
||||
help='Specifies the indent level to use when pretty-printing output'),
|
||||
)
|
||||
|
@ -14,7 +16,6 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, *app_labels, **options):
|
||||
from django.db.models import get_app, get_apps, get_models
|
||||
from django.core import serializers
|
||||
|
||||
format = options.get('format', 'json')
|
||||
indent = options.get('indent', None)
|
||||
|
@ -26,6 +27,9 @@ class Command(BaseCommand):
|
|||
|
||||
# Check that the serialization format exists; this is a shortcut to
|
||||
# avoid collating all the objects and _then_ failing.
|
||||
if format not in self.serializer_formats:
|
||||
raise CommandError("Unknown serialization format: %s" % format)
|
||||
|
||||
try:
|
||||
serializers.get_serializer(format)
|
||||
except KeyError:
|
||||
|
|
|
@ -50,10 +50,10 @@ class Command(BaseCommand):
|
|||
parts = fixture_label.split('.')
|
||||
if len(parts) == 1:
|
||||
fixture_name = fixture_label
|
||||
formats = serializers.get_serializer_formats()
|
||||
formats = serializers.get_public_serializer_formats()
|
||||
else:
|
||||
fixture_name, format = '.'.join(parts[:-1]), parts[-1]
|
||||
if format in serializers.get_serializer_formats():
|
||||
if format in serializers.get_public_serializer_formats():
|
||||
formats = [format]
|
||||
else:
|
||||
formats = []
|
||||
|
|
|
@ -53,6 +53,11 @@ def get_serializer_formats():
|
|||
_load_serializers()
|
||||
return _serializers.keys()
|
||||
|
||||
def get_public_serializer_formats():
|
||||
if not _serializers:
|
||||
_load_serializers()
|
||||
return [k for k, v in _serializers.iteritems() if not v.Serializer.internal_use_only]
|
||||
|
||||
def get_deserializer(format):
|
||||
if not _serializers:
|
||||
_load_serializers()
|
||||
|
|
|
@ -22,6 +22,10 @@ class Serializer(object):
|
|||
Abstract serializer base class.
|
||||
"""
|
||||
|
||||
# Indicates if the implemented serializer is only available for
|
||||
# internal Django use.
|
||||
internal_use_only = False
|
||||
|
||||
def serialize(self, queryset, **options):
|
||||
"""
|
||||
Serialize a queryset.
|
||||
|
|
|
@ -20,6 +20,8 @@ class Serializer(PythonSerializer):
|
|||
"""
|
||||
Convert a queryset to JSON.
|
||||
"""
|
||||
internal_use_only = False
|
||||
|
||||
def end_serialization(self):
|
||||
self.options.pop('stream', None)
|
||||
self.options.pop('fields', None)
|
||||
|
|
|
@ -13,7 +13,9 @@ class Serializer(base.Serializer):
|
|||
"""
|
||||
Serializes a QuerySet to basic Python objects.
|
||||
"""
|
||||
|
||||
|
||||
internal_use_only = True
|
||||
|
||||
def start_serialization(self):
|
||||
self._current = None
|
||||
self.objects = []
|
||||
|
|
|
@ -19,6 +19,8 @@ class Serializer(PythonSerializer):
|
|||
Convert a queryset to YAML.
|
||||
"""
|
||||
|
||||
internal_use_only = False
|
||||
|
||||
def handle_field(self, obj, field):
|
||||
# A nasty special case: base YAML doesn't support serialization of time
|
||||
# types (as opposed to dates or datetimes, which it does support). Since
|
||||
|
|
Loading…
Reference in New Issue