def get_node_by_id(self, id, nodes, namespace=None): final_node = None try: for node in nodes: if node.id == id: if namespace: if node.namespace == namespace: final_node = node break else: final_node = node break if final_node is None: """ If we're editing a page, we need to find the draft version of the page and turn it into a navigation node """ page = get_page_draft(Page.objects.get(id=id)) final_node = page_to_node(page, page, 0) final_node.children = [] final_node.parent = [] except: logger.exception('Failed to find node') return final_node
def get_context(self, context, template): try: # If there's an exception (500), default context_processors may not be called. request = context['request'] except KeyError: return {'template': 'menu/empty.html'} page = request.current_page print "page", page # print dir(page) print page.parent print "children", page.get_children() print "current page", page print type(request.current_page) node = page_to_node(page, page, None) children = cut_levels([node], 0, 100, 0, 1) children = apply_modifiers(children, request, None, None, post_cut=True) try: context.update({'children':children, 'template':template,}) except: context = {"template":template} return context
def get_nodes(self, request): usr, nodes = request.user, [] # much of this init code is the same as cms/menu.py to ensure # result compatibility # don't need to pass in request, since the tag app is only here # to help organize articles, not assist in moderation flow. page_queryset = get_page_queryset() site = Site.objects.get_current() lang = get_language_from_request(request) filters = {"site": site} if settings.CMS_HIDE_UNTRANSLATED: filters["title_set__language"] = lang pages = ( page_queryset.published() .filter(**filters) .order_by( "-creation_date", # "tree_id", # "lft", ) ) # menu-building helper vars append = nodes.append counter = CountingID(1) new_id = counter.get # Create nodes for tags and related pages in one pass for tag in Tag.objects.all(): # 1. node for tag node_id = new_id() append( NavigationNode( tag.name, reverse("xue.tagfrontend.views.tag_view", args=(tag.pk,)), node_id, # make the pages referrable from CMS templates! attr={"reverse_id": "cmstag_%s" % tag.name}, ) ) # 2. related pages # we'll reuse CMS's page_to_node but modify the # result node slightly for page in pages.filter(tags=tag): # get the node as it's returned by the CMS # TODO: is the simplified params appropriate? page_node = page_to_node(page, page, False) # modify it to fit in our tree structure page_node.id = new_id() page_node.parent_id = node_id append(page_node) return nodes
def get_node_by_id(self, id, nodes): final_node = None for node in nodes: if node.id == id: final_node = node break if final_node is None: """ If we're editing a page, we need to find the draft version of the page and turn it into a navigation node """ page = get_page_draft(Page.objects.get(id=id)) final_node = page_to_node(page, page, 0) final_node.children = [] final_node.parent = [] return final_node