Opened 9 years ago

Closed 8 years ago

#3071 closed defect (fixed)

[patch] Context should have the __contains__ method

Reported by: akaihola Owned by: adrian
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: UI/UX:

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)

context_contains.diff (422 bytes) - added by akaihola 9 years ago.
Adds the contains method for Context

Download all attachments as: .zip

Change History (5)

Changed 9 years ago by akaihola

Adds the contains method for Context

comment:1 Changed 9 years ago by SmileyChris

  • Summary changed from Context should have the __contains__ method to [patch] Context should have the __contains__ method

comment:2 Changed 9 years ago by adrian

  • Component changed from Core framework to Template system

comment:3 Changed 9 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:4 Changed 8 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [4480]) Fixed #3071 -- added a __contains__ method to the Context class. Thanks
akaihola.

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