Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #8847, #10370: added some missing methods to MultiValueDict aft…

…er [8399]. Thanks, James Turk and rfk.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 184ea1c91f06d31d0e1d34b2c27c08b01d2d5033 1 parent 9ae873f
@jacobian jacobian authored
View
11 django/utils/datastructures.py
@@ -294,10 +294,19 @@ def lists(self):
"""Returns a list of (key, list) pairs."""
return super(MultiValueDict, self).items()
+ def iterlists(self):
+ """Yields (key, list) pairs."""
+ return super(MultiValueDict, self).iteritems()
+
def values(self):
"""Returns a list of the last value on every key list."""
return [self[key] for key in self.keys()]
-
+
+ def itervalues(self):
+ """Yield the last value on every key list."""
+ for key in self.iterkeys():
+ yield self[key]
+
def copy(self):
"""Returns a copy of this object."""
return self.__deepcopy__()
View
33 docs/ref/request-response.txt
@@ -14,11 +14,11 @@ Django uses request and response objects to pass state through the system.
When a page is requested, Django creates an :class:`HttpRequest` object that
contains metadata about the request. Then Django loads the appropriate view,
-passing the :class:`HttpRequest` as the first argument to the view function. Each
-view is responsible for returning an :class:`HttpResponse` object.
+passing the :class:`HttpRequest` as the first argument to the view function.
+Each view is responsible for returning an :class:`HttpResponse` object.
-This document explains the APIs for :class:`HttpRequest` and :class:`HttpResponse`
-objects.
+This document explains the APIs for :class:`HttpRequest` and
+:class:`HttpResponse` objects.
HttpRequest objects
===================
@@ -103,7 +103,8 @@ All attributes except ``session`` should be considered read-only.
* ``read(num_bytes=None)`` -- Read a number of bytes from the file.
* ``name`` -- The name of the uploaded file.
* ``size`` -- The size, in bytes, of the uploaded file.
- * ``chunks(chunk_size=None)`` -- A generator that yields sequential chunks of data.
+ * ``chunks(chunk_size=None)`` -- A generator that yields sequential
+ chunks of data.
See :ref:`topics-files` for more information.
@@ -229,9 +230,10 @@ Methods
.. versionadded:: 1.0
- Returns ``True`` if the request was made via an ``XMLHttpRequest``, by checking
- the ``HTTP_X_REQUESTED_WITH`` header for the string ``'XMLHttpRequest'``. The
- following major JavaScript libraries all send this header:
+ Returns ``True`` if the request was made via an ``XMLHttpRequest``, by
+ checking the ``HTTP_X_REQUESTED_WITH`` header for the string
+ ``'XMLHttpRequest'``. The following major JavaScript libraries all send this
+ header:
* jQuery
* Dojo
@@ -317,6 +319,17 @@ a subclass of dictionary. Exceptions are outlined here:
>>> q = QueryDict('a=1&a=2&a=3')
>>> q.items()
[('a', '3')]
+
+.. method:: QueryDict.iteritems()
+
+ Just like the standard dictionary ``iteritems()`` method. Like
+ :meth:`QueryDict.items()` this uses the same last-value logic as
+ :meth:`QueryDict.__getitem()__`.
+
+.. method:: QueryDict.iterlists()
+
+ Like :meth:`QueryDict.iteritems()` except it includes all values, as a list,
+ for each member of the dictionary.
.. method:: QueryDict.values()
@@ -327,6 +340,10 @@ a subclass of dictionary. Exceptions are outlined here:
>>> q.values()
['3']
+.. method:: QueryDict.itervalues()
+
+ Just like :meth:`QueryDict.values()`, except an iterator.
+
In addition, ``QueryDict`` has the following methods:
.. method:: QueryDict.copy()
View
6 tests/regressiontests/datastructures/tests.py
@@ -45,6 +45,8 @@
['Adrian', 'Simon']
>>> list(d.iteritems())
[('position', 'Developer'), ('name', 'Simon')]
+>>> list(d.iterlists())
+[('position', ['Developer']), ('name', ['Adrian', 'Simon'])]
>>> d['lastname']
Traceback (most recent call last):
...
@@ -58,6 +60,10 @@
>>> d.setlist('lastname', ['Holovaty', 'Willison'])
>>> d.getlist('lastname')
['Holovaty', 'Willison']
+>>> d.values()
+['Developer', 'Simon', 'Willison']
+>>> list(d.itervalues())
+['Developer', 'Simon', 'Willison']
### SortedDict #################################################################
Please sign in to comment.
Something went wrong with that request. Please try again.