Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OrderedDict where available instead #157

Merged
merged 1 commit into from
Oct 7, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions import_export/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from diff_match_patch import diff_match_patch

from django.utils.safestring import mark_safe
from django.utils.datastructures import SortedDict
from django.utils import six
from django.db import transaction
from django.db.models.fields import FieldDoesNotExist
Expand All @@ -30,6 +29,10 @@
except ImportError:
from django.utils.encoding import force_unicode as force_text

try:
from collections import OrderedDict
except ImportError:
from django.utils.datastructures import SortedDict as OrderedDict

USE_TRANSACTIONS = getattr(settings, 'IMPORT_EXPORT_USE_TRANSACTIONS', False)

Expand Down Expand Up @@ -103,7 +106,7 @@ def __new__(cls, name, bases, attrs):
field.column_name = field_name
declared_fields.append((field_name, field))

attrs['fields'] = SortedDict(declared_fields)
attrs['fields'] = OrderedDict(declared_fields)
new_class = super(DeclarativeMetaclass, cls).__new__(cls, name,
bases, attrs)
opts = getattr(new_class, 'Meta', None)
Expand Down Expand Up @@ -431,7 +434,7 @@ def __new__(cls, name, bases, attrs):
readonly=False)
field_list.append((f.name, field, ))

new_class.fields.update(SortedDict(field_list))
new_class.fields.update(OrderedDict(field_list))

#add fields that follow relationships
if opts.fields is not None:
Expand Down Expand Up @@ -468,7 +471,7 @@ def __new__(cls, name, bases, attrs):
readonly=True)
field_list.append((field_name, field))

new_class.fields.update(SortedDict(field_list))
new_class.fields.update(OrderedDict(field_list))

return new_class

Expand Down Expand Up @@ -551,3 +554,4 @@ def modelresource_factory(model, resource_class=ModelResource):

metaclass = ModelDeclarativeMetaclass
return metaclass(class_name, (resource_class,), class_attrs)