Ticket #6580: fix6580.patch

File fix6580.patch, 1.9 KB (added by Matthias Kestenholz, 14 years ago)
  • django/utils/datastructures.py

    diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
    index 30ce28d..9f250f2 100644
    a b class MultiValueDict(dict):  
    230230    'Simon'
    231231    >>> d.getlist('name')
    232232    ['Adrian', 'Simon']
     233    >>> d.getlist('doesnotexist')
     234    []
     235    >>> d.getlist('doesnotexist', ['Adrian', 'Simon'])
     236    ['Adrian', 'Simon']
    233237    >>> d.get('lastname', 'nonexistent')
    234238    'nonexistent'
    235239    >>> d.setlist('lastname', ['Holovaty', 'Willison'])
    class MultiValueDict(dict):  
    300304            return default
    301305        return val
    302306
    303     def getlist(self, key):
     307    def getlist(self, key, default=None):
    304308        """
    305309        Returns the list of values for the passed key. If key doesn't exist,
    306         then an empty list is returned.
     310        the default value is returned.
    307311        """
    308312        try:
    309313            return super(MultiValueDict, self).__getitem__(key)
    310314        except KeyError:
     315            if default is not None:
     316                return default
    311317            return []
    312318
    313319    def setlist(self, key, list_):
  • docs/ref/request-response.txt

    diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
    index 380210d..6232ba8 100644
    a b In addition, ``QueryDict`` has the following methods:  
    356356    standard library. The copy will be mutable -- that is, you can change its
    357357    values.
    358358
    359 .. method:: QueryDict.getlist(key)
     359.. method:: QueryDict.getlist(key, default)
    360360
    361361    Returns the data with the requested key, as a Python list. Returns an
    362     empty list if the key doesn't exist. It's guaranteed to return a list of
    363     some sort.
     362    empty list if the key doesn't exist and no default value was provided.
     363    It's guaranteed to return a list of some sort unless the default value
     364    was no list.
    364365
    365366.. method:: QueryDict.setlist(key, list_)
    366367
Back to Top