diff options
| author | Aymeric Augustin <aymeric.augustin@oscaro.com> | 2015-02-10 10:29:00 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@oscaro.com> | 2015-02-10 14:35:05 +0100 |
| commit | 9b7b37382cb0e8b5e2d149a3102005bf62016ea3 (patch) | |
| tree | 68bb5be8cb0573348c330ac7b2d0015f2bef3fbd /django/template/context.py | |
| parent | a8b70d251d238b4e6cfc7bb4296da15494f8dff3 (diff) | |
[1.8.x] Split DTL context creation into its own function.
This reduces the length of rope RequestContext gives users to hang
themselves with.
Thanks Alex Hill for the report and Tim Graham for the review.
Backport of f2c104a from master.
Diffstat (limited to 'django/template/context.py')
| -rw-r--r-- | django/template/context.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/django/template/context.py b/django/template/context.py index aff8aa2e1c..01d21a159a 100644 --- a/django/template/context.py +++ b/django/template/context.py @@ -234,3 +234,19 @@ class RequestContext(Context): if hasattr(new_context, '_processors_index'): del new_context._processors_index return new_context + + +def make_context(context, request=None): + """ + Create a suitable Context from a plain dict and optionally an HttpRequest. + """ + if request is None: + context = Context(context) + else: + # The following pattern is required to ensure values from + # context override those from template context processors. + original_context = context + context = RequestContext(request) + if original_context: + context.push(original_context) + return context |
