Skip to content

Commit b07afea

Browse files
author
Bernardo Cabezas
committed
support dynamic template extensions, for django-easy-pjax integration
1 parent 4605250 commit b07afea

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

cms/utils/plugins.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
from django.shortcuts import get_object_or_404
88
from django.template import (NodeList, TextNode, VariableNode,
99
TemplateSyntaxError)
10+
from django.template import Context
1011
from django.template.loader import get_template
1112
from django.template.loader_tags import (ConstantIncludeNode, ExtendsNode,
1213
BlockNode)
1314
import warnings
14-
from sekizai.helpers import is_variable_extend_node
15+
#from sekizai.helpers import is_variable_extend_node
1516

1617
def get_page_from_plugin_or_404(cms_plugin):
1718
return get_object_or_404(Page, placeholders=cms_plugin.placeholder)
@@ -21,9 +22,10 @@ def _extend_blocks(extend_node, blocks):
2122
Extends the dictionary `blocks` with *new* blocks in the parent node (recursive)
2223
"""
2324
# we don't support variable extensions
24-
if is_variable_extend_node(extend_node):
25-
return
26-
parent = extend_node.get_parent(None)
25+
#if is_variable_extend_node(extend_node):
26+
# return
27+
context = Context({'request':True})
28+
parent = extend_node.get_parent(context)
2729
# Search for new blocks
2830
for node in parent.nodelist.get_nodes_by_type(BlockNode):
2931
if not node.name in blocks:
@@ -42,21 +44,22 @@ def _extend_blocks(extend_node, blocks):
4244
break
4345

4446
def _find_topmost_template(extend_node):
45-
parent_template = extend_node.get_parent({})
47+
context = Context({'request':1})
48+
parent_template = extend_node.get_parent(context)
4649
for node in parent_template.nodelist.get_nodes_by_type(ExtendsNode):
4750
# Their can only be one extend block in a template, otherwise django raises an exception
4851
return _find_topmost_template(node)
4952
# No ExtendsNode
50-
return extend_node.get_parent({})
53+
return extend_node.get_parent(context)
5154

5255
def _extend_nodelist(extend_node):
5356
"""
5457
Returns a list of placeholders found in the parent template(s) of this
5558
ExtendsNode
5659
"""
5760
# we don't support variable extensions
58-
if is_variable_extend_node(extend_node):
59-
return []
61+
#if is_variable_extend_node(extend_node):
62+
# return []
6063
blocks = extend_node.blocks
6164
_extend_blocks(extend_node, blocks)
6265
placeholders = []

0 commit comments

Comments
 (0)