mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #35417 -- Updated BaseContext.new() with values to create a context that can be flattened.
This commit is contained in:
parent
8733e9af99
commit
2a32b23382
1
AUTHORS
1
AUTHORS
@ -375,6 +375,7 @@ answer newbie questions, and generally made Django that much better:
|
||||
George Karpenkov <george@metaworld.ru>
|
||||
George Song <george@damacy.net>
|
||||
George Vilches <gav@thataddress.com>
|
||||
George Y. Kussumoto <georgeyk.dev@gmail.com>
|
||||
Georg "Hugo" Bauer <gb@hugo.westfalen.de>
|
||||
Georgi Stanojevski <glisha@gmail.com>
|
||||
Gerardo Orozco <gerardo.orozco.mosqueda@gmail.com>
|
||||
|
@ -31,7 +31,9 @@ class BaseContext:
|
||||
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):
|
||||
|
@ -158,6 +158,17 @@ class ContextTests(SimpleTestCase):
|
||||
},
|
||||
)
|
||||
|
||||
def test_flatten_context_with_context_copy(self):
|
||||
ctx1 = Context({"a": 2})
|
||||
ctx2 = ctx1.new(Context({"b": 4}))
|
||||
self.assertEqual(
|
||||
ctx2.dicts, [{"True": True, "False": False, "None": None}, {"b": 4}]
|
||||
)
|
||||
self.assertEqual(
|
||||
ctx2.flatten(),
|
||||
{"False": False, "None": None, "True": True, "b": 4},
|
||||
)
|
||||
|
||||
def test_context_comparable(self):
|
||||
"""
|
||||
#21765 -- equality comparison should work
|
||||
|
Loading…
Reference in New Issue
Block a user