Fixed #709 -- Added a __contains__ method to MultiValueDict. Thanks, Brantley

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1498 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-11-30 00:19:15 +00:00
parent e2e98aff6a
commit 674ac13ca6
2 changed files with 9 additions and 2 deletions

View File

@ -81,6 +81,9 @@ class MultiValueDict:
def __len__(self): def __len__(self):
return len(self.data) return len(self.data)
def __contains__(self, key):
return self.data.has_key(key)
def get(self, key, default): def get(self, key, default):
"Returns the default value if the requested data doesn't exist" "Returns the default value if the requested data doesn't exist"
try: try:

View File

@ -31,11 +31,11 @@ All attributes except ``session`` should be considered read-only.
``GET`` ``GET``
A dictionary-like object containing all given HTTP GET parameters. See the A dictionary-like object containing all given HTTP GET parameters. See the
``MultiValueDict`` documentation below. ``QueryDict`` documentation below.
``POST`` ``POST``
A dictionary-like object containing all given HTTP POST parameters. See the A dictionary-like object containing all given HTTP POST parameters. See the
``MultiValueDict`` documentation below. ``QueryDict`` documentation below.
``REQUEST`` ``REQUEST``
For convenience, a dictionary-like object that searches ``POST`` first, For convenience, a dictionary-like object that searches ``POST`` first,
@ -150,6 +150,10 @@ directly.
* ``__setitem__(key, value)`` -- Sets the given key to ``[value]`` * ``__setitem__(key, value)`` -- Sets the given key to ``[value]``
(a Python list whose single element is ``value``). (a Python list whose single element is ``value``).
* ``__contains__(key)`` -- **New in Django development version.*** Returns
``True`` if the given key exists. This lets you do, e.g.,
``if "foo" in request.GET``.
* ``__len__()`` * ``__len__()``
* ``get(key, default)`` -- Uses the same logic as ``__getitem__()`` above, * ``get(key, default)`` -- Uses the same logic as ``__getitem__()`` above,