Esempio n. 1
0
        def _make_menu_item_handling_many_package_types(menu_item, title, **kw):
            # See ckan/lib/helpers.py:545

            _menu_items = config['routes.named_routes']
            if menu_item not in _menu_items:
                raise Exception('menu item `%s` cannot be found' % menu_item)
            item = copy.copy(_menu_items[menu_item])
            item.update(kw)
            active = h._link_active(item)

            if c.controller == 'package' and len(menu_item) > 7:
                # Guess type of package
                if request.path == '/':
                    type = 'dataset'

                else:
                    parts = [x for x in request.path.split('/') if x]
                    if len(parts[0]) == 2: # is it locale? simple check
                        type = parts[1]
                    else:
                        type = parts[0]

                active = type == menu_item[:-7] # assuming menu_item == '<type>_search'

            needed = item.pop('needed')
            for need in needed:
                if need not in kw:
                    raise Exception('menu item `%s` need parameter `%s`'
                                    % (menu_item, need))
            link = h._link_to(title, menu_item, suppress_active_class=True, **item)
            if active:
                return literal('<li class="active">') + link + literal('</li>')
            return literal('<li>') + link + literal('</li>')
Esempio n. 2
0
def _make_menu_item(menu_item, title, literal_start, literal_end,
                    literal_start_active, literal_end_active, **kw):
    ''' build a navigation item used for example breadcrumbs

    outputs <div class="main-menu__item"><a href="..."></i> title</a></li>

    :param menu_item: the name of the defined menu item defined in
    config/routing as the named route of the same name
    :type menu_item: string
    :param title: text used for the link
    :type title: string
    :param **kw: additional keywords needed for creating url eg id=...

    :rtype: HTML literal

    This function is called by wrapper functions.
    '''
    menu_item = map_pylons_to_flask_route_name(menu_item)
    _menu_items = toolkit.config['routes.named_routes']
    if menu_item not in _menu_items:
        raise Exception('menu item `%s` cannot be found' % menu_item)
    item = copy.copy(_menu_items[menu_item])
    item.update(kw)
    active = _link_active(item)
    needed = item.pop('needed')
    for need in needed:
        if need not in kw:
            raise Exception('menu item `%s` need parameter `%s`' %
                            (menu_item, need))
    link = _link_to(title, menu_item, suppress_active_class=True, **item)
    if active:
        return literal(literal_start_active) + link + literal(
            literal_end_active)
    return literal(literal_start) + link + literal(literal_end)
Esempio n. 3
0
def _make_menu_tab(menu_item, title, **kw):
    ''' build a navigation item used for example breadcrumbs

    outputs <div class="main-menu__item"><a href="..."></i> title</a></li>

    :param menu_item: the name of the defined menu item defined in
    config/routing as the named route of the same name
    :type menu_item: string
    :param title: text used for the link
    :type title: string
    :param **kw: additional keywords needed for creating url eg id=...

    :rtype: HTML literal

    This function is called by wrapper functions.
    '''
    menu_item = map_pylons_to_flask_route_name(menu_item)
    _menu_items = toolkit.config['routes.named_routes']
    if menu_item not in _menu_items:
        raise Exception('menu item `%s` cannot be found' % menu_item)
    item = copy.copy(_menu_items[menu_item])
    item.update(kw)
    # link = _link_to(title, menu_item, **item)
    kwargs = {'action': item['action'], 'controller': item['controller']}
    kwargs.update(kw)
    if 'offset' in item:
        kwargs["offset"] = item['offset']
    if 'id' in item:
        kwargs["id"] = item['id']
    if 'resource_id' in item:
        kwargs["resource_id"] = item['resource_id']
    link = toolkit.url_for(menu_item, **kwargs)
    active = _link_active(item)

    return link, active
Esempio n. 4
0
def _make_menu_item_cread(menu_item, title, **kw):
    ''' build a navigation item used for example breadcrumbs

    outputs <li><a href="..."></i> title</a></li>

    :param menu_item: the name of the defined menu item defined in
    config/routing as the named route of the same name
    :type menu_item: string
    :param title: text used for the link
    :type title: string
    :param **kw: additional keywords needed for creating url eg id=...

    :rtype: HTML literal

    This function is called by wrapper functions.
    '''
    _menu_items = h.config['routes.named_routes']
    if menu_item not in _menu_items:
        raise Exception('menu item `%s` cannot be found' % menu_item)
    item = h.copy.copy(_menu_items[menu_item])
    item.update(kw)
    active = h._link_active(item)
    needed = item.pop('needed')
    for need in needed:
        if need not in kw:
            raise Exception('menu item `%s` need parameter `%s`'
                            % (menu_item, need))
    link = h._link_to(title, menu_item, suppress_active_class=True, **item)
    
    ##log.info('::::::::::::::::::::::::::: %r', menu_item)
	
    if active:
        return h.literal('<li class="active_cread">') + link + h.literal('</li>')
    
    if menu_item == "search": 
 	return h.literal('<li class="blue_bg">') + link + h.literal('</li>')
    if menu_item == "organizations_index":
	return h.literal('<li class="blue_bg">') + link + h.literal('</li>')	

    return h.literal('<li class="green_bg">') + link + h.literal('</li>')
Esempio n. 5
0
        def _make_menu_item_handling_many_package_types(
                menu_item, title, **kw):
            # See ckan/lib/helpers.py:545

            _menu_items = config['routes.named_routes']
            if menu_item not in _menu_items:
                raise Exception('menu item `%s` cannot be found' % menu_item)
            item = copy.copy(_menu_items[menu_item])
            item.update(kw)
            active = h._link_active(item)

            if c.controller == 'package' and len(menu_item) > 7:
                # Guess type of package
                if request.path == '/':
                    type = 'dataset'

                else:
                    parts = [x for x in request.path.split('/') if x]
                    if len(parts[0]) == 2:  # is it locale? simple check
                        type = parts[1]
                    else:
                        type = parts[0]

                active = type == menu_item[:
                                           -7]  # assuming menu_item == '<type>_search'

            needed = item.pop('needed')
            for need in needed:
                if need not in kw:
                    raise Exception('menu item `%s` need parameter `%s`' %
                                    (menu_item, need))
            link = h._link_to(title,
                              menu_item,
                              suppress_active_class=True,
                              **item)
            if active:
                return literal('<li class="active">') + link + literal('</li>')
            return literal('<li>') + link + literal('</li>')
Esempio n. 6
0
def is_route_active(menu_item):
    _menu_items = config.get('routes.named_routes')
    if menu_item not in _menu_items:
        return False
    return helpers._link_active(_menu_items[menu_item])
Esempio n. 7
0
def is_route_active(menu_item):
    _menu_items = config.get('routes.named_routes')
    if menu_item not in _menu_items:
        return False
    return helpers._link_active(_menu_items[menu_item])