def build_pages_nav_main(*args): about_menu = tk.asbool(tk.config.get('ckanext.pages.about_menu', True)) group_menu = tk.asbool(tk.config.get('ckanext.pages.group_menu', True)) org_menu = tk.asbool(tk.config.get('ckanext.pages.organization_menu', True)) # Different CKAN versions use different route names - gotta catch em all! about_menu_routes = ['about', 'home.about'] group_menu_routes = ['group_index', 'home.group_index'] org_menu_routes = ['organizations_index', 'home.organizations_index'] new_args = [] for arg in args: if arg[0] in about_menu_routes and not about_menu: continue if arg[0] in org_menu_routes and not org_menu: continue if arg[0] in group_menu_routes and not group_menu: continue new_args.append(arg) output = core_build_nav_main(*new_args) # do not display any private pages in menu even for sysadmins pages_list = tk.get_action('ckanext_pages_list')(None, {'order': True, 'private': False}) page_name = '' if ckan_29_or_higher: is_current_page = tk.get_endpoint() in (('pages', 'show'), ('pages', 'blog_show')) else: is_current_page = ( hasattr(tk.c, 'action') and tk.c.action in ('pages_show', 'blog_show') and tk.c.controller == 'ckanext.pages.controller:PagesController') if is_current_page: page_name = tk.request.path.split('/')[-1] for page in pages_list: type_ = 'blog' if page['page_type'] == 'blog' else 'pages' if six.PY2: name = quote(page['name'].encode('utf-8')).decode('utf-8') else: name = quote(page['name']) title = html_escape(page['title']) link = tk.h.literal(u'<a href="/{}/{}">{}</a>'.format(type_, name, title)) if page['name'] == page_name: li = tk.literal('<li class="active">') + link + tk.literal('</li>') else: li = tk.literal('<li>') + link + tk.literal('</li>') output = output + li return output
def validation_extract_report_from_errors(errors): report = None for error in errors.keys(): if error == 'validation': report = errors[error][0] # Remove full path from table source source = report['tables'][0]['source'] report['tables'][0]['source'] = source.split('/')[-1] msg = _(''' There are validation issues with this file, please see the <a {params}>report</a> for details. Once you have resolved the issues, click the button below to replace the file.''') params = [ 'href="#validation-report"', 'data-module="modal-dialog"', 'data-module-div="validation-report-dialog"', ] new_error = literal(msg.format(params=' '.join(params))) errors[error] = [new_error] break return report, errors