def get_navigation_object_from_page(page: Page, current_page_id: int) -> dict: page_object = { "text": str(page.title), "nodes": [], "href": page.get_url(), "state": {} } if isinstance(page.specific, PageWithSidebar) or isinstance( page.specific, LessonPage) or isinstance(page.specific, ArticlePage): menu_title = page.specific.menu_title if not isinstance(menu_title, str): menu_title = menu_title.decode() if menu_title != '': page_object["text"] = menu_title if not page.specific.is_selectable: page_object["selectable"] = False if page.id == current_page_id: page_object["state"] = {"selected": True} page_object["selectable"] = False for child in page.get_children(): if child.show_in_menus: page_object["nodes"].append( get_navigation_object_from_page(child, current_page_id)) if len(page_object["nodes"]) == 0: page_object.pop('nodes', None) return page_object
def get_navigation_object_from_page(page: Page, current_page_id: int) -> dict: page_object = { "text": str(page.title), "nodes": [], "href": page.get_url(), "state": {} } if isinstance(page.specific, PageWithSidebar) or isinstance(page.specific, LessonPage) or isinstance(page.specific, ArticlePage): menu_title = page.specific.menu_title if not isinstance(menu_title, str): menu_title = menu_title.decode() if menu_title != '': page_object["text"] = menu_title if not page.specific.is_selectable: page_object["selectable"] = False if page.id == current_page_id: page_object["state"] = { "selected": True } page_object["selectable"] = False for child in page.get_children(): if child.show_in_menus: page_object["nodes"].append(get_navigation_object_from_page(child, current_page_id)) if len(page_object["nodes"]) == 0: page_object.pop('nodes', None) return page_object
def get_menue(self, page: Page): siblings = page.get_root().get_siblings(inclusive=True).filter( live=True, show_in_menus=True) root_kids = page.get_root().get_children().filter(live=True, show_in_menus=True) menus = page.get_children().filter( live=True, show_in_menus=True) | siblings | root_kids print(menus) return menus