#5138 closed (fixed)
Add __contains__ to HttpRequest to make it more dict-like
Reported by: | anonymous | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Design decision needed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If I try to evaluate the view method
def index(request): if 'foo' in request: ...
I the error "0 not found in either POST or GET." Adding the following method to HttpRequest
def __contains__(self, key): return self.has_key(key)
fixes that problem. Please add that method to make the request behavior more dict
-like.
Attachments (1)
Change History (7)
comment:1 by , 17 years ago
Summary: | in operator doesn't work with HttpRequest → Add __contains__ to HttpRequest to make it more dict-like |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 17 years ago
comment:3 by , 17 years ago
Has patch: | set |
---|
This caught me out as well today. I think it's a good idea to enable, and then promote, the use of "in" over the "has_key" method since dict.has_key() is being depreciated.
I'm also attaching a patch to achieve this.
by , 17 years ago
Attachment: | HttpRequest-contains.patch added |
---|
Patch to add contains method to HttpResquest
comment:4 by , 17 years ago
(In [6097]) Fixed #5138 -- Added contains method to HttpRequest, mirroring existing has_key method. Thanks for the patch, robbie@…. NOTE: Original checkin message incorrectly referenced bug #5318.
comment:5 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:6 by , 17 years ago
(In [6098]) Refs #5138 -- Refactored implementation of contains in HttpRequest introduced in [6097] after a suggestion from Malcolm. Applied a similar refactor for MergeDict and Context which had comparable behavior.
租房 减速机 热血江湖私服