1
0
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:
George Y. Kussumoto 2024-06-04 15:07:01 -03:00 committed by Sarah Boyce
parent 8733e9af99
commit 2a32b23382
3 changed files with 15 additions and 1 deletions

View File

@ -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>

View File

@ -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):

View File

@ -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