Ticket #6580: 6580.patch

File 6580.patch, 3.5 KB (added by Matthias Kestenholz, 16 years ago)
  • django/utils/datastructures.py

    diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
    index f27bc1c..073c3da 100644
    a b class MultiValueDict(dict):  
    172172    'Simon'
    173173    >>> d.getlist('name')
    174174    ['Adrian', 'Simon']
     175    >>> d.getlist('doesnotexist')
     176    []
     177    >>> d.getlist('doesnotexist', ['Adrian', 'Simon'])
     178    ['Adrian', 'Simon']
    175179    >>> d.get('lastname', 'nonexistent')
    176180    'nonexistent'
    177181    >>> d.setlist('lastname', ['Holovaty', 'Willison'])
    class MultiValueDict(dict):  
    231235            return default
    232236        return val
    233237
    234     def getlist(self, key):
     238    def getlist(self, key, default=None):
    235239        """
    236240        Returns the list of values for the passed key. If key doesn't exist,
    237241        then an empty list is returned.
    class MultiValueDict(dict):  
    239243        try:
    240244            return super(MultiValueDict, self).__getitem__(key)
    241245        except KeyError:
     246            if default is not None:
     247                return default
    242248            return []
    243249
    244250    def setlist(self, key, list_):
  • docs/request_response.txt

    diff --git a/docs/request_response.txt b/docs/request_response.txt
    index 54fc24d..1c3640c 100644
    a b All attributes except ``session`` should be considered read-only.  
    8080    strings.
    8181
    8282``FILES``
    83    
     83
    8484    .. admonition:: Changed in Django development version
    85        
     85
    8686        In previous versions of Django, ``request.FILES`` contained
    8787        simple ``dict`` objects representing uploaded files. This is
    8888        no longer true -- files are represented by ``UploadedFile``
    8989        objects as described below.
    90        
     90
    9191        These ``UploadedFile`` objects will emulate the old-style ``dict``
    9292        interface, but this is deprecated and will be removed in the next
    9393        release of Django.
    94        
     94
    9595    A dictionary-like object containing all uploaded files. Each key in
    9696    ``FILES`` is the ``name`` from the ``<input type="file" name="" />``. Each
    9797    value in ``FILES`` is an ``UploadedFile`` object containing the following
    All attributes except ``session`` should be considered read-only.  
    102102        * ``file_size`` -- The size, in bytes, of the uploaded file.
    103103        * ``chunk()`` -- A generator that yields sequential chunks of data.
    104104
    105     See `File Uploads`_ for more information. 
    106    
     105    See `File Uploads`_ for more information.
     106
    107107    Note that ``FILES`` will only contain data if the request method was POST
    108108    and the ``<form>`` that posted to the request had
    109109    ``enctype="multipart/form-data"``. Otherwise, ``FILES`` will be a blank
    110110    dictionary-like object.
    111    
     111
    112112    .. _File Uploads: ../upload_handling/
    113113
    114114``META``
    In addition, ``QueryDict`` has the following methods:  
    305305      from the Python standard library. The copy will be mutable -- that is,
    306306      you can change its values.
    307307
    308     * ``getlist(key)`` -- Returns the data with the requested key, as a Python
    309       list. Returns an empty list if the key doesn't exist. It's guaranteed to
    310       return a list of some sort.
     308    * ``getlist(key, default)`` -- Returns the data with the requested key, as
     309      a Python list. Returns an empty list if the key doesn't exist and no
     310      default value was provided. It's guaranteed to return a list of some sort
     311      unless the default value was no list.
    311312
    312313    * ``setlist(key, list_)`` -- Sets the given key to ``list_`` (unlike
    313314      ``__setitem__()``).
Back to Top