# Path: philo/templatetags/containers.py
# class ContainerNode(template.Node):
# 	def __init__(self, name, references=None, as_var=None):
# 		self.name = name
# 		self.as_var = as_var
# 		self.references = references
# 	
# 	def render(self, context):
# 		container_content = self.get_container_content(context)
# 		
# 		if self.as_var:
# 			context[self.as_var] = container_content
# 			return ''
# 		
# 		return container_content
# 	
# 	def get_container_content(self, context):
# 		try:
# 			container_context = context.render_context[CONTAINER_CONTEXT_KEY]
# 		except KeyError:
# 			try:
# 				page = context['page']
# 			except KeyError:
# 				return settings.TEMPLATE_STRING_IF_INVALID
# 			
# 			container_context = ContainerContext(page)
# 			context.render_context[CONTAINER_CONTEXT_KEY] = container_context
# 		
# 		if self.references:
# 			# Then it's a content reference.
# 			try:
# 				contentreference = container_context.get_references()[(self.name, self.references)]
# 			except KeyError:
# 				content = ''
# 			else:
# 				content = contentreference.content
# 		else:
# 			# Otherwise it's a contentlet.
# 			try:
# 				contentlet = container_context.get_contentlets()[self.name]
# 			except KeyError:
# 				content = ''
# 			else:
# 				content = contentlet.content
# 		return content


import itertools
from django.template import TextNode, VariableNode, Context
from django.template.loader_tags import BlockNode, ExtendsNode, BlockContext, ConstantIncludeNode
from django.utils.datastructures import SortedDict
from philo.templatetags.containers import ContainerNode




LOADED_TEMPLATE_ATTR = '_philo_loaded_template'
BLANK_CONTEXT = Context()


def get_extended(self):
	return self.get_parent(BLANK_CONTEXT)


def get_included(self):
	return self.template


# We ignore the IncludeNode because it will never work in a blank context.
setattr(ExtendsNode, LOADED_TEMPLATE_ATTR, property(get_extended))
setattr(ConstantIncludeNode, LOADED_TEMPLATE_ATTR, property(get_included))


def get_containers(template):
		# Build a tree of the templates we're using, placing the root template first.
		levels = build_extension_tree(template.nodelist)
		
		contentlet_specs = []
		contentreference_specs = SortedDict()
		blocks = {}
		

# Path: philo/templatetags/containers.py
# class ContainerNode(template.Node):
# 	def __init__(self, name, references=None, as_var=None):
# 		self.name = name
# 		self.as_var = as_var
# 		self.references = references
# 	
# 	def render(self, context):
# 		container_content = self.get_container_content(context)
# 		
# 		if self.as_var:
# 			context[self.as_var] = container_content
# 			return ''
# 		
# 		return container_content
# 	
# 	def get_container_content(self, context):
# 		try:
# 			container_context = context.render_context[CONTAINER_CONTEXT_KEY]
# 		except KeyError:
# 			try:
# 				page = context['page']
# 			except KeyError:
# 				return settings.TEMPLATE_STRING_IF_INVALID
# 			
# 			container_context = ContainerContext(page)
# 			context.render_context[CONTAINER_CONTEXT_KEY] = container_context
# 		
# 		if self.references:
# 			# Then it's a content reference.
# 			try:
# 				contentreference = container_context.get_references()[(self.name, self.references)]
# 			except KeyError:
# 				content = ''
# 			else:
# 				content = contentreference.content
# 		else:
# 			# Otherwise it's a contentlet.
# 			try:
# 				contentlet = container_context.get_contentlets()[self.name]
# 			except KeyError:
# 				content = ''
# 			else:
# 				content = contentlet.content
# 		return content


# Path: philo/utils/templates.py
import itertools
from django.template import TextNode, VariableNode, Context
from django.template.loader_tags import BlockNode, ExtendsNode, BlockContext, ConstantIncludeNode
from django.utils.datastructures import SortedDict
from philo.templatetags.containers import ContainerNode





LOADED_TEMPLATE_ATTR = '_philo_loaded_template'
BLANK_CONTEXT = Context()


def get_extended(self):
	return self.get_parent(BLANK_CONTEXT)


def get_included(self):
	return self.template


# We ignore the IncludeNode because it will never work in a blank context.
setattr(ExtendsNode, LOADED_TEMPLATE_ATTR, property(get_extended))
setattr(ConstantIncludeNode, LOADED_TEMPLATE_ATTR, property(get_included))


def get_containers(template):
		# Build a tree of the templates we're using, placing the root template first.
		levels = build_extension_tree(template.nodelist)
		
		contentlet_specs = []
		contentreference_specs = SortedDict()
		blocks = {}
		

		for level in reversed(levels):