Opened 19 years ago
Closed 19 years ago
#3071 closed defect (fixed)
[patch] Context should have the __contains__ method
| Reported by: | Antti Kaihola | Owned by: | Adrian Holovaty | 
|---|---|---|---|
| Component: | Template system | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
The Context class in django.template.context should have a __contains__ method defined, so that one can do:
if 'missiles' not in context:
    raise ImproperlyConfigured, \
        'Please include missiles in the context so we can destroy the world.'
    destroy_world_with(context['missiles'])
Although, the destroy_world_with function is left as an exercise for the reader.
A simple patch which concerns context.py is included.
Attachments (1)
Change History (5)
by , 19 years ago
| Attachment: | context_contains.diff added | 
|---|
comment:1 by , 19 years ago
| Summary: | Context should have the __contains__ method → [patch] Context should have the __contains__ method | 
|---|
comment:2 by , 19 years ago
| Component: | Core framework → Template system | 
|---|
comment:3 by , 19 years ago
| Triage Stage: | Unreviewed → Ready for checkin | 
|---|
comment:4 by , 19 years ago
| Resolution: | → fixed | 
|---|---|
| Status: | new → closed | 
  Note:
 See   TracTickets
 for help on using tickets.
    
Adds the contains method for Context