Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#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)

HttpRequest-contains.patch (533 bytes ) - added by robbie@… 17 years ago.
Patch to add contains method to HttpResquest

Download all attachments as: .zip

Change History (7)

comment:1 by Simon G. <dev@…>, 17 years ago

Summary: in operator doesn't work with HttpRequestAdd __contains__ to HttpRequest to make it more dict-like
Triage Stage: UnreviewedDesign decision needed

comment:3 by robbie@…, 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 robbie@…, 17 years ago

Attachment: HttpRequest-contains.patch added

Patch to add contains method to HttpResquest

comment:4 by Russell Keith-Magee, 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 Russell Keith-Magee, 17 years ago

Resolution: fixed
Status: newclosed

comment:6 by Russell Keith-Magee, 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.

Note: See TracTickets for help on using tickets.
Back to Top