Ticket #12820: mergedict_patch.diff

File mergedict_patch.diff, 1.3 KB (added by sztamas, 6 years ago)
  • django/utils/datastructures.py

     
     1import itertools
    12from types import GeneratorType
    23
    34from django.utils.copycompat import deepcopy
     
    3738                return dict_.getlist(key)
    3839        return []
    3940
     41    def __iter__(self):
     42        seen = set()
     43        for key in itertools.chain.from_iterable(self.dicts):
     44            if key not in seen:
     45                seen.add(key)
     46                yield key
     47
    4048    def items(self):
    4149        item_list = []
    4250        for dict_ in self.dicts:
  • tests/regressiontests/datastructures/tests.py

     
    3434>>> mm.getlist('undefined')
    3535[]
    3636
     37MergeDict supports iterating on keys
     38>>> [(k,mm.getlist(k)) for k in mm]
     39[('key2', ['value2', 'value3']), ('key1', ['value1']), ('key4', ['value5', 'value6'])]
     40
    3741### MultiValueDict ##########################################################
    3842
    3943>>> d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']})
Back to Top