diff --git a/AUTHORS b/AUTHORS index 9d47f2c876..94659c88fa 100644 --- a/AUTHORS +++ b/AUTHORS @@ -83,6 +83,7 @@ answer newbie questions, and generally made Django that much better: Russell Cloran colin@owlfish.com crankycoder@gmail.com + Paul Collier Pete Crosier Matt Croydon flavio.curella@gmail.com diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index ac890d5da6..40e99c3962 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -72,12 +72,23 @@ class SortedDict(dict): def items(self): return zip(self.keyOrder, self.values()) + def iteritems(self): + for key in self.keyOrder: + yield key, dict.__getitem__(self, key) + def keys(self): return self.keyOrder[:] + def iterkeys(self): + return iter(self.keyOrder) + def values(self): return [dict.__getitem__(self, k) for k in self.keyOrder] + def itervalues(self): + for key in self.keyOrder: + yield dict.__getitem__(self, key) + def update(self, dict): for k, v in dict.items(): self.__setitem__(k, v) @@ -91,6 +102,15 @@ class SortedDict(dict): "Returns the value of the item at the given zero-based index." return self[self.keyOrder[index]] + def insert(self, index, key, value): + "Inserts the key, value pair before the item with the given index." + if key in self.keyOrder: + n = self.keyOrder.index(key) + del self.keyOrder[n] + if n < index: index -= 1 + self.keyOrder.insert(index, key) + dict.__setitem__(self, key, value) + def copy(self): "Returns a copy of this object." # This way of initializing the copy means it works for subclasses, too.