Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from csomme/context-new-accept-context-19
Browse files Browse the repository at this point in the history
Allow Context to take another Context instance in new
  • Loading branch information
csomme authored Aug 8, 2016
2 parents e8bb746 + c459292 commit 0f0491b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion django/template/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def __init__(self, dict_=None):
def _reset_dicts(self, value=None):
builtins = {'True': True, 'False': False, 'None': None}
self.dicts = [builtins]
if value is not None:
if isinstance(value, BaseContext):
self.dicts += value.dicts[1:]
elif value is not None:
self.dicts.append(value)

def __copy__(self):
Expand Down
15 changes: 14 additions & 1 deletion tests/template_tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_flatten_context(self):
a.update({'b': 4})
a.update({'c': 8})

self.assertEqual(a.flatten(), {
self.assertDictEqual(a.flatten(), {
'False': False, 'None': None, 'True': True,
'a': 2, 'b': 4, 'c': 8
})
Expand All @@ -150,6 +150,19 @@ def test_flatten_context_with_context(self):
'z': '8',
})

def test_flatten_context_new_context(self):
"""
Context.new with a Context argument should work.
"""
a = Context({'a': 2})
b = a.new(Context({'b': 4}))
self.assertEqual(b.flatten(), {
'False': False,
'None': None,
'True': True,
'b': 4
})

def test_context_comparable(self):
"""
#21765 -- equality comparison should work
Expand Down

0 comments on commit 0f0491b

Please sign in to comment.