Skip to content

Commit

Permalink
Merge branch 'pjax' into apsl
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardo Cabezas committed Aug 21, 2012
2 parents a052f59 + b07afea commit e08f77b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cms/utils/plugins.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.template import (NodeList, TextNode, VariableNode, from django.template import (NodeList, TextNode, VariableNode,
TemplateSyntaxError) TemplateSyntaxError)
from django.template import Context
from django.template.loader import get_template from django.template.loader import get_template
from django.template.loader_tags import (ConstantIncludeNode, ExtendsNode, from django.template.loader_tags import (ConstantIncludeNode, ExtendsNode,
BlockNode) BlockNode)
import warnings import warnings
from sekizai.helpers import is_variable_extend_node #from sekizai.helpers import is_variable_extend_node


def get_page_from_plugin_or_404(cms_plugin): def get_page_from_plugin_or_404(cms_plugin):
return get_object_or_404(Page, placeholders=cms_plugin.placeholder) return get_object_or_404(Page, placeholders=cms_plugin.placeholder)
Expand All @@ -21,9 +22,10 @@ def _extend_blocks(extend_node, blocks):
Extends the dictionary `blocks` with *new* blocks in the parent node (recursive) Extends the dictionary `blocks` with *new* blocks in the parent node (recursive)
""" """
# we don't support variable extensions # we don't support variable extensions
if is_variable_extend_node(extend_node): #if is_variable_extend_node(extend_node):
return # return
parent = extend_node.get_parent(None) context = Context({'request':True})
parent = extend_node.get_parent(context)
# Search for new blocks # Search for new blocks
for node in parent.nodelist.get_nodes_by_type(BlockNode): for node in parent.nodelist.get_nodes_by_type(BlockNode):
if not node.name in blocks: if not node.name in blocks:
Expand All @@ -42,21 +44,22 @@ def _extend_blocks(extend_node, blocks):
break break


def _find_topmost_template(extend_node): def _find_topmost_template(extend_node):
parent_template = extend_node.get_parent({}) context = Context({'request':1})
parent_template = extend_node.get_parent(context)
for node in parent_template.nodelist.get_nodes_by_type(ExtendsNode): for node in parent_template.nodelist.get_nodes_by_type(ExtendsNode):
# Their can only be one extend block in a template, otherwise django raises an exception # Their can only be one extend block in a template, otherwise django raises an exception
return _find_topmost_template(node) return _find_topmost_template(node)
# No ExtendsNode # No ExtendsNode
return extend_node.get_parent({}) return extend_node.get_parent(context)


def _extend_nodelist(extend_node): def _extend_nodelist(extend_node):
""" """
Returns a list of placeholders found in the parent template(s) of this Returns a list of placeholders found in the parent template(s) of this
ExtendsNode ExtendsNode
""" """
# we don't support variable extensions # we don't support variable extensions
if is_variable_extend_node(extend_node): #if is_variable_extend_node(extend_node):
return [] # return []
blocks = extend_node.blocks blocks = extend_node.blocks
_extend_blocks(extend_node, blocks) _extend_blocks(extend_node, blocks)
placeholders = [] placeholders = []
Expand Down

0 comments on commit e08f77b

Please sign in to comment.