def render(self, context): try: nav_node = context['nav_node'] except: raise ValueError, "the variable 'nav_node' must exist in the context and be assigned to the object currently being viewed in the navigation" self.content_type = content_type_slug_for_obj(nav_node) self.menus = dict((menu.get("name"), menu) for menu in self.tree.getiterator("menu")) self.navigation = self.menus['navigation'] self.parent_map = dict((c, p) for p in self.tree.getiterator() for c in p) # home page self.home_page = self.navigation[0] # hard-code section pages to be the direct sub-elements of the home page. self.section_pages = self.home_page.getchildren() self.current_node = None self.current_section_node = None self.current_path = list() for node in self.navigation.getiterator("node"): if str(node.get("contenttype")) == str(self.content_type) and int(node.get("objectid")) == int(nav_node.id): self.current_node = n = node while n.tag == "node": self.current_path.append(n) if(self.parent_map[n] == self.home_page): self.current_section_node = n n = self.parent_map[n] self.current_path.reverse() return getattr(self, self.mode)()
def __init__(self): super(Command, self).__init__() self.style = no_style() self.content_type = content_type_slug_for_obj(Page) self.default_user = User.objects.get(id=1)