1
1
from django .template .loader_tags import BlockNode , ExtendsNode
2
2
from django .template import loader , Context , RequestContext
3
+ from django .http import HttpResponse
3
4
5
+ from django .template .base import SimpleNode
4
6
5
7
6
8
class BlockNotFound (Exception ):
@@ -25,15 +27,15 @@ def render_template_blocks_nodelist(nodelist, block_list, context):
25
27
26
28
for node in nodelist :
27
29
print "node class: %s" % node .__class__ .__name__
28
-
30
+
29
31
if isinstance (node , BlockNode ) and node .name in block_list :
30
32
print "node name: %s" % node .name
31
33
block_map .setdefault (node .name , node .render (context ))
32
34
33
35
for key in ('nodelist' , 'nodelist_true' , 'nodelist_false' ):
34
36
if hasattr (node , key ):
35
37
try :
36
- inner_block_map = render_template_block_nodelist (getattr (node , key ), block_list , context )
38
+ inner_block_map = render_template_blocks_nodelist (getattr (node , key ), block_list , context )
37
39
except :
38
40
pass
39
41
else :
@@ -44,7 +46,7 @@ def render_template_blocks_nodelist(nodelist, block_list, context):
44
46
for node in nodelist :
45
47
if isinstance (node , ExtendsNode ):
46
48
try :
47
- inner_block_map = render_template_block (node .get_parent (context ), block_list , context )
49
+ inner_block_map = render_template_blocks (node .get_parent (context ), block_list , context )
48
50
except BlockNotFound :
49
51
pass
50
52
else :
@@ -58,7 +60,6 @@ def render_block_to_string(template_name, block_list, dictionary={}, context_ins
58
60
Loads the given template_name and renders the given block with the given dictionary as
59
61
context. Returns a string.
60
62
"""
61
- dictionary = dictionary or {}
62
63
template = get_template (template_name )
63
64
64
65
if context_instance is not None :
@@ -68,15 +69,15 @@ def render_block_to_string(template_name, block_list, dictionary={}, context_ins
68
69
69
70
template .render (context_instance )
70
71
71
- return render_template_block (template , block_list , context_instance )
72
+ return render_template_blocks (template , block_list , context_instance )
72
73
73
- def direct_block_to_template (request , template , block , extra_context = None , mimetype = None , ** kwargs ):
74
+ def direct_block_to_template (request , template , block_list , extra_context = None , mimetype = None , ** kwargs ):
74
75
"""
75
76
Render a given block in a given template with any extra URL parameters in the context as
76
77
``{{ params }}``.
77
78
"""
78
79
if extra_context is None :
79
- extra_context = {}
80
+ extra_context = {}
80
81
dictionary = {'params' : kwargs }
81
82
for key , value in extra_context .items ():
82
83
if callable (value ):
@@ -86,4 +87,4 @@ def direct_block_to_template(request, template, block, extra_context=None, mimet
86
87
c = RequestContext (request , dictionary )
87
88
t = get_template (template )
88
89
t .render (c )
89
- return HttpResponse (render_template_block (t , block , c ), mimetype = mimetype )
90
+ return HttpResponse (render_template_blocks (t , block_list , c ), mimetype = mimetype )
0 commit comments