From 8b67f5f829a998c860e107173584dcc4346d1225 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 27 Sep 2005 16:33:25 +0000 Subject: [PATCH] Fixed #567 -- Added HttpRequest.has_key() method. Thanks, wojtek3@brandlay.com git-svn-id: http://code.djangoproject.com/svn/django/trunk@711 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/httpwrappers.py | 3 +++ docs/request_response.txt | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/django/utils/httpwrappers.py b/django/utils/httpwrappers.py index 2312891b6a..eeebda565d 100644 --- a/django/utils/httpwrappers.py +++ b/django/utils/httpwrappers.py @@ -20,6 +20,9 @@ class HttpRequest(object): # needs to be new-style class because subclasses defi return d[key] raise KeyError, "%s not found in either POST or GET" % key + def has_key(self, key): + return self.GET.has_key(key) or self.POST.has_key(key) + def get_full_path(self): return '' diff --git a/docs/request_response.txt b/docs/request_response.txt index 5b01fc3482..150a5bc92c 100644 --- a/docs/request_response.txt +++ b/docs/request_response.txt @@ -110,6 +110,18 @@ All attributes except ``session`` should be considered read-only. Methods ------- +``__getitem__(key)`` + Returns the GET/POST value for the given key, checking POST first, then + GET. Raises ``KeyError`` if the key doesn't exist. + + This lets you use dictionary-accessing syntax on an ``HttpRequest`` + instance. Example: ``request["foo"]`` would return ``True`` if either + ``request.POST`` or ``request.GET`` had a ``"foo"`` key. + +``has_key()`` + Returns ``True`` or ``False``, designating whether ``request.GET`` or + ``request.POST`` has the given key. + ``get_full_path()`` Returns the ``path``, plus an appended query string, if applicable.