summaryrefslogtreecommitdiff
path: root/django/utils/datastructures.py
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-05-22 15:05:29 +0000
committerJannis Leidel <jannis@leidel.info>2011-05-22 15:05:29 +0000
commitfc8116cc4f5f27911c7685649ebac0a96fb39a49 (patch)
tree93e27b7d1ee8a206851a96dde3b6f934e59af95d /django/utils/datastructures.py
parent80d60890290768267230dfcff7e70a1343fdbc25 (diff)
Fixed #6580 -- Added `default` parameter to `MultiValueDict.getlist` method (the base class for `QueryDict`). Many thanks to mk and andrewebdev.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16260 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/datastructures.py')
-rw-r--r--django/utils/datastructures.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index ff281b032a..b0b449c76d 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -228,6 +228,10 @@ class MultiValueDict(dict):
'Simon'
>>> d.getlist('name')
['Adrian', 'Simon']
+ >>> d.getlist('doesnotexist')
+ []
+ >>> d.getlist('doesnotexist', ['Adrian', 'Simon'])
+ ['Adrian', 'Simon']
>>> d.get('lastname', 'nonexistent')
'nonexistent'
>>> d.setlist('lastname', ['Holovaty', 'Willison'])
@@ -300,14 +304,16 @@ class MultiValueDict(dict):
return default
return val
- def getlist(self, key):
+ def getlist(self, key, default=None):
"""
Returns the list of values for the passed key. If key doesn't exist,
- then an empty list is returned.
+ then a default value is returned.
"""
try:
return super(MultiValueDict, self).__getitem__(key)
except KeyError:
+ if default is not None:
+ return default
return []
def setlist(self, key, list_):