aboutsummaryrefslogtreecommitdiffstats
path: root/main/py-django-oscar/0002-Don-t-use-django.template.Context-for-template-rende.patch
blob: 17aed9912be7f1625b75f39a7d0e4946c9a8fdc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
From d2d5b17dcac857503b3040dabc7c93d567c68054 Mon Sep 17 00:00:00 2001
From: Michael van Tellingen <michael@mvantellingen.nl>
Date: Tue, 4 Apr 2017 23:27:38 +0200
Subject: [PATCH 2/8] Don't use django.template.Context for template rendering

Since Django 1.11 dicts should be passed to template rendering functions
---
 src/oscar/apps/customer/abstract_models.py |  5 +++--
 src/oscar/apps/customer/alerts/utils.py    | 10 +++++-----
 src/oscar/forms/widgets.py                 |  5 ++---
 src/oscar/templatetags/product_tags.py     |  2 ++
 4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/oscar/apps/customer/abstract_models.py b/src/oscar/apps/customer/abstract_models.py
index fbebf60..9a6c5ee 100644
--- a/src/oscar/apps/customer/abstract_models.py
+++ b/src/oscar/apps/customer/abstract_models.py
@@ -6,7 +6,7 @@ from django.contrib.auth import models as auth_models
 from django.core.urlresolvers import reverse
 from django.core.validators import RegexValidator
 from django.db import models
-from django.template import Context, Template, TemplateDoesNotExist
+from django.template import Template, TemplateDoesNotExist
 from django.template.loader import get_template
 from django.utils import six, timezone
 from django.utils.encoding import python_2_unicode_compatible
@@ -238,8 +238,9 @@ class AbstractCommunicationEventType(models.Model):
             settings, 'OSCAR_STATIC_BASE_URL', None)
 
         messages = {}
+        ctx = {}
         for name, template in templates.items():
-            messages[name] = template.render(Context(ctx)) if template else ''
+            messages[name] = template.render(ctx) if template else ''
 
         # Ensure the email subject doesn't contain any newlines
         messages['subject'] = messages['subject'].replace("\n", "")
diff --git a/src/oscar/apps/customer/alerts/utils.py b/src/oscar/apps/customer/alerts/utils.py
index fc3d8bf..776d811 100644
--- a/src/oscar/apps/customer/alerts/utils.py
+++ b/src/oscar/apps/customer/alerts/utils.py
@@ -4,7 +4,7 @@ from django.conf import settings
 from django.contrib.sites.models import Site
 from django.core import mail
 from django.db.models import Max
-from django.template import Context, loader
+from django.template import loader
 
 from oscar.apps.customer.notifications import services
 from oscar.core.loading import get_class, get_model
@@ -32,10 +32,10 @@ def send_alert_confirmation(alert):
     """
     Send an alert confirmation email.
     """
-    ctx = Context({
+    ctx = {
         'alert': alert,
         'site': Site.objects.get_current(),
-    })
+    }
     subject_tpl = loader.get_template('customer/alerts/emails/'
                                       'confirmation_subject.txt')
     body_tpl = loader.get_template('customer/alerts/emails/'
@@ -93,11 +93,11 @@ def send_product_alerts(product):
         if not data.availability.is_available_to_buy:
             continue
 
-        ctx = Context({
+        ctx = {
             'alert': alert,
             'site': Site.objects.get_current(),
             'hurry': hurry_mode,
-        })
+        }
         if alert.user:
             # Send a site notification
             num_notifications += 1
diff --git a/src/oscar/forms/widgets.py b/src/oscar/forms/widgets.py
index 85ba1b0..5b374cf 100644
--- a/src/oscar/forms/widgets.py
+++ b/src/oscar/forms/widgets.py
@@ -4,7 +4,6 @@ from django import forms
 from django.core.files.uploadedfile import InMemoryUploadedFile
 from django.forms.utils import flatatt
 from django.forms.widgets import FileInput
-from django.template import Context
 from django.template.loader import render_to_string
 from django.utils import formats, six
 from django.utils.encoding import force_text
@@ -42,11 +41,11 @@ class ImageInput(FileInput):
             image_url = final_attrs['value'] = force_text(
                 self._format_value(value))
 
-        return render_to_string(self.template_name, Context({
+        return render_to_string(self.template_name, {
             'input_attrs': flatatt(final_attrs),
             'image_url': image_url,
             'image_id': "%s-image" % final_attrs['id'],
-        }))
+        })
 
 
 class WYSIWYGTextArea(forms.Textarea):
diff --git a/src/oscar/templatetags/product_tags.py b/src/oscar/templatetags/product_tags.py
index ea5c3f2..8fa6f66 100644
--- a/src/oscar/templatetags/product_tags.py
+++ b/src/oscar/templatetags/product_tags.py
@@ -23,6 +23,8 @@ def render_product(context, product):
              % product.get_product_class().slug,
              'catalogue/partials/product.html']
     template_ = select_template(names)
+    context = context.flatten()
+
     # Ensure the passed product is in the context as 'product'
     context['product'] = product
     return template_.render(context)
-- 
2.9.4