Added STATIC_URL to context for icons.
[philo.git] / models / pages.py
index 4da5e99..86db88f 100644 (file)
@@ -12,26 +12,30 @@ from philo.models.base import TreeModel, register_value_model
 from philo.models.fields import TemplateField
 from philo.models.nodes import View
 from philo.templatetags.containers import ContainerNode
-from philo.utils import fattr, nodelist_crawl
+from philo.utils import fattr
 from philo.validators import LOADED_TEMPLATE_ATTR
 from philo.signals import page_about_to_render_to_string, page_finished_rendering_to_string
 
 
 class LazyContainerFinder(object):
-       _created = 0
-       _initialized = 0
-       
-       def __init__(self, nodes):
-               self.__class__._created += 1
+       def __init__(self, nodes, extends=False):
                self.nodes = nodes
                self.initialized = False
                self.contentlet_specs = set()
                self.contentreference_specs = SortedDict()
                self.blocks = {}
                self.block_super = False
+               self.extends = extends
        
        def process(self, nodelist):
                for node in nodelist:
+                       if self.extends:
+                               if isinstance(node, BlockNode):
+                                       self.blocks[node.name] = block = LazyContainerFinder(node.nodelist)
+                                       block.initialize()
+                                       self.blocks.update(block.blocks)
+                               continue
+                       
                        if isinstance(node, ContainerNode):
                                if not node.references:
                                        self.contentlet_specs.add(node.name)
@@ -40,17 +44,6 @@ class LazyContainerFinder(object):
                                                self.contentreference_specs[node.name] = node.references
                                continue
                        
-                       if isinstance(node, BlockNode):
-                               #if nodelist == self.nodes: Necessary?
-                               self.blocks[node.name] = block = LazyContainerFinder(node.nodelist)
-                               if block.nodes.get_nodes_by_type(BlockNode): # Is this faster?
-                                       block.initialize()
-                                       self.blocks.update(block.blocks)
-                               continue
-                       
-                       if isinstance(node, ExtendsNode):
-                               continue
-                       
                        if isinstance(node, VariableNode):
                                if node.filter_expression.var.lookups == (u'block', u'super'):
                                        self.block_super = True
@@ -74,7 +67,6 @@ class LazyContainerFinder(object):
                if not self.initialized:
                        self.process(self.nodes)
                        self.initialized = True
-                       self.__class__._initialized += 1
 
 
 class Template(TreeModel):
@@ -104,7 +96,7 @@ class Template(TreeModel):
                        
                        if extends:
                                if extends.nodelist:
-                                       nodelists.append(LazyContainerFinder(extends.nodelist))
+                                       nodelists.append(LazyContainerFinder(extends.nodelist, extends=True))
                                loaded_template = getattr(extends, LOADED_TEMPLATE_ATTR)
                                nodelists.extend(build_extension_tree(loaded_template.nodelist))
                        else:
@@ -138,7 +130,7 @@ class Template(TreeModel):
                return contentlet_specs, contentreference_specs
        
        def __unicode__(self):
-               return self.get_path(pathsep=u' › ', field='name')
+               return self.name
        
        class Meta:
                app_label = 'philo'