1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Made the new template.Context.flatten() method a public API.

That method was introduced in 9db4271bd1.

Refs #21765.
This commit is contained in:
Marek Wywiał
2014-02-16 14:50:27 +01:00
committed by Baptiste Mispelon
parent 57ba5bf97b
commit 8274fa60f8
4 changed files with 66 additions and 7 deletions

View File

@@ -97,6 +97,15 @@ class BaseContext(object):
new_context._reset_dicts(values)
return new_context
def flatten(self):
"""
Returns self.dicts as one dictionary
"""
flat = {}
for d in self.dicts:
flat.update(d)
return flat
def __eq__(self, other):
"""
Compares two contexts by comparing theirs 'dicts' attributes.
@@ -104,13 +113,7 @@ class BaseContext(object):
if isinstance(other, BaseContext):
# because dictionaries can be put in different order
# we have to flatten them like in templates
def flatten(dicts):
flat = {}
for d in dicts:
flat.update(d)
return flat
return flatten(self.dicts) == flatten(other.dicts)
return self.flatten() == other.flatten()
# if it's not comparable return false
return False