def render_external_navigation(current_key): if not use_external_navigation(): return None api = RESTAPI() base = config.get('adhocracy.external_navigation_base') try: result = api.staticpages_get(base=base) except ConnectionError as e: log.error('Error while connecting to static pages backend: %s' % e) return None if not result.ok: log.error('Error while fetching static pages: %s %s' % (result.status_code, result.reason)) return None try: nav = result.json() except JSONDecodeError as e: log.error('Error while decoding static pages: %s' % e) return None instance = c.instance if instance_staticpages_api_address() else None if nav is None or not nav.get('children'): log.error('External navigation not found for configured languages') return None def render_navigation_item(item, path='', toplevel=False): from adhocracy.lib.templating import render_def if path != '': path = '%s/%s' % (path, item['name']) else: path = item['name'] url = _url.build(instance, 'static', path, format='html') contains_current = (path == current_key) if item['children']: children, contained_list = izip( *map(lambda child: render_navigation_item(child, path), item['children'])) contains_current = contains_current or any(contained_list) else: children = [] html = render_def('static/tiles.html', 'navigation_item', href=url, title=item['title'], current=toplevel and contains_current, children=children) return (html, contains_current) html_list, _ = izip( *map(lambda child: render_navigation_item(child, toplevel=True), nav['children'])) return '\n'.join(html_list)
def render_external_navigation(current_key): api = RESTAPI() base = config.get('adhocracy.kotti_navigation_base', None) result = api.staticpages_get(base=base) nav = result.json() if nav is None or not nav.get('children'): log.error('External navigation not found for configured languages') return '' def render_navigation_item(item, path='', toplevel=False): from adhocracy.lib.templating import render_def if path != '': path = '%s/%s' % (path, item['name']) else: path = item['name'] url = '/static/%s.html' % path contains_current = (path == current_key) if item['children']: children, contained_list = izip( *map(lambda child: render_navigation_item(child, path), item['children'])) contains_current = contains_current or any(contained_list) else: children = [] html = render_def('static/tiles.html', 'navigation_item', href=url, title=item['title'], current=toplevel and contains_current, children=children) return (html, contains_current) html_list, _ = izip( *map(lambda child: render_navigation_item(child, toplevel=True), nav['children'])) return '\n'.join(html_list)