Django

Code

Changeset 7062

Show
Ignore:
Timestamp:
02/02/08 20:02:41 (5 months ago)
Author:
mtredinnick
Message:

Fixed #6465 -- Tweaked MergeDict?.getlist() to work with Django's MultiValueDict? class. Thanks, Matt McClanahan?.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/utils/datastructures.py

    r6800 r7062  
    33    A simple class for creating new "virtual" dictionaries that actually look 
    44    up values in more than one dictionary, passed in the constructor. 
     5 
     6    If a key appears in more than one of the passed in dictionaries, only the 
     7    first occurrence will be used. 
    58    """ 
    69    def __init__(self, *dicts): 
     
    2629    def getlist(self, key): 
    2730        for dict_ in self.dicts: 
    28             try
     31            if key in dict_.keys()
    2932                return dict_.getlist(key) 
    30             except KeyError: 
    31                 pass 
    32         raise KeyError 
     33        return [] 
    3334 
    3435    def items(self): 
  • django/trunk/tests/regressiontests/datastructures/tests.py

    r6715 r7062  
    2020>>> md2['chris'] 
    2121'cool' 
     22 
     23MergeDict can merge MultiValueDicts 
     24>>> multi1 = MultiValueDict({'key1': ['value1'], 'key2': ['value2', 'value3']}) 
     25>>> multi2 = MultiValueDict({'key2': ['value4'], 'key4': ['value5', 'value6']}) 
     26>>> mm = MergeDict(multi1, multi2) 
     27 
     28# Although 'key2' appears in both dictionaries, only the first value is used. 
     29>>> mm.getlist('key2') 
     30['value2', 'value3'] 
     31>>> mm.getlist('key4') 
     32['value5', 'value6'] 
     33>>> mm.getlist('undefined') 
     34[] 
    2235 
    2336### MultiValueDict ##########################################################