diff options
| author | Marek WywiaĆ <onjinx@gmail.com> | 2014-02-16 14:50:27 +0100 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2014-02-16 15:18:45 +0100 |
| commit | 8274fa60f88607eb0e81908f049c391455956dd8 (patch) | |
| tree | 7405dd7591d3b710e19d758c153231e2063789a0 /django | |
| parent | 57ba5bf97b13acdaccd6e091e6f23b619a6faedb (diff) | |
Made the new template.Context.flatten() method a public API.
That method was introduced in 9db4271bd11ac23a5a5652bbcdf8fb6d4b997651.
Refs #21765.
Diffstat (limited to 'django')
| -rw-r--r-- | django/template/context.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/django/template/context.py b/django/template/context.py index b2f00abd31..76af916cb7 100644 --- a/django/template/context.py +++ b/django/template/context.py @@ -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 |
