aboutsummaryrefslogtreecommitdiffstats
path: root/main/py-django-oscar/0009-Fix-the-render_promotion-template-tag.patch
blob: 6ff74a8c4f9454474433d594078b1c9f18e72a7f (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
From e76a83621f6b099a33949304792adb4b6fe35a9d Mon Sep 17 00:00:00 2001
From: Michael van Tellingen <michael@mvantellingen.nl>
Date: Tue, 7 Feb 2017 23:04:25 +0100
Subject: [PATCH 09/11] Fix the render_promotion template-tag

---
 src/oscar/templatetags/promotion_tags.py | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/src/oscar/templatetags/promotion_tags.py b/src/oscar/templatetags/promotion_tags.py
index a4d7f77..95f9df6 100644
--- a/src/oscar/templatetags/promotion_tags.py
+++ b/src/oscar/templatetags/promotion_tags.py
@@ -1,26 +1,19 @@
-from django.template import Library, Node, RequestContext, Variable
+from django.template import Library, Node, RequestContext
 from django.template.loader import select_template
 
 register = Library()
 
 
-class PromotionNode(Node):
-    def __init__(self, promotion):
-        self.promotion_var = Variable(promotion)
+@register.simple_tag(takes_context=True)
+def render_promotion(context, promotion):
+    template = select_template([
+        promotion.template_name(), 'promotions/default.html'])
 
-    def render(self, context):
-        promotion = self.promotion_var.resolve(context)
-        template = select_template([promotion.template_name(),
-                                    'promotions/default.html'])
-        args = {'promotion': promotion}
-        args.update(**promotion.template_context(request=context['request']))
-        ctx = RequestContext(context['request'], args)
-        return template.render(ctx)
+    args = {
+        'request': context['request'],
+        'promotion': promotion
+    }
+    args.update(**promotion.template_context(request=context['request']))
 
-
-def get_promotion_html(parser, token):
-    _, promotion = token.split_contents()
-    return PromotionNode(promotion)
-
-
-register.tag('render_promotion', get_promotion_html)
+    ctx = RequestContext(context['request'], args)
+    return template.render(ctx)
-- 
2.9.4