Skip to content

Commit fd6b23a

Browse files
benspauldingacdha
authored andcommitted
Prefer stdlib OrderedDict over Django's SortedDict
The two are not exactly they same, but they are equivalent for Haystack's needs.
1 parent 06360a0 commit fd6b23a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

haystack/utils/loading.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@
88

99
from django.conf import settings
1010
from django.core.exceptions import ImproperlyConfigured
11-
from django.utils.datastructures import SortedDict
1211
from django.utils.module_loading import module_has_submodule
1312

1413
from haystack.exceptions import NotHandled, SearchFieldError
1514
from haystack.utils import importlib
1615
from haystack.utils.app_loading import haystack_get_app_modules
1716

1817

18+
try:
19+
# Introduced in Python 2.7
20+
from collections import OrderedDict
21+
except ImportError:
22+
# Deprecated in Django 1.8; removed in Django 1.9 (both of which require
23+
# at least Python 2.7)
24+
from django.utils.datastructures import SortedDict as OrderedDict
25+
26+
1927
def import_class(path):
2028
path_bits = path.split('.')
2129
# Cut off the class name at the end.
@@ -152,7 +160,7 @@ class UnifiedIndex(object):
152160
# Used to collect all the indexes into a cohesive whole.
153161
def __init__(self, excluded_indexes=None):
154162
self._indexes = {}
155-
self.fields = SortedDict()
163+
self.fields = OrderedDict()
156164
self._built = False
157165
self.excluded_indexes = excluded_indexes or []
158166
self.excluded_indexes_ids = {}
@@ -192,7 +200,7 @@ def collect_indexes(self):
192200

193201
def reset(self):
194202
self._indexes = {}
195-
self.fields = SortedDict()
203+
self.fields = OrderedDict()
196204
self._built = False
197205
self._fieldnames = {}
198206
self._facet_fieldnames = {}

0 commit comments

Comments
 (0)