Skip to content

Commit

Permalink
new build_nav_main() helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed May 17, 2012
1 parent c353f80 commit 6fcb736
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -11,6 +11,8 @@
import re
import urllib
import pprint
import copy
import logging

from paste.deploy.converters import asbool
from webhelpers.html import escape, HTML, literal, url_escape
Expand Down Expand Up @@ -40,6 +42,8 @@
get_available_locales = i18n.get_available_locales
get_locales_dict = i18n.get_locales_dict

log = logging.getLogger(__name__)

try:
from collections import OrderedDict # from python 2.7
except ImportError:
Expand Down Expand Up @@ -347,9 +351,41 @@ def _subnav_named_route(text, routename, **kwargs):
class_=('active' if c.action == kwargs['action'] else '')
)

def build_nav_main(*args):
output = ''
for item in args:
menu_item, title = item
output += _make_menu_item(menu_item, title)
return output


def _make_menu_item(menu_item, title):
if menu_item not in _menu_items:
log.error('menu item `%s` cannot be found' % menu_item)
return literal('<li><a href="#">') + title + literal('</a></li>')
item = copy.copy(_menu_items[menu_item])
if 'name' in item:
link = nav_named_link(title, **item)
else:
controller = item.pop('controller')
link = nav_link(title, controller, **item)
return literal('<li>') + link + literal('</li>')


def default_group_type():
return str( config.get('ckan.default.group_type', 'group') )


_menu_items = {
'search' : dict(controller='package',
action='search',
highlight_actions = 'new index search'),
'default_group': dict(name='%s_index' % default_group_type()),
'about' : dict(controller='home', action='about'),
}



def unselected_facet_items(facet, limit=10):
'''Return the list of unselected facet items for the given facet, sorted
by count.
Expand Down Expand Up @@ -861,6 +897,7 @@ def debug_inspect(arg):
'lang_native_name',
'unselected_facet_items',
'include_resource',
'build_nav_main',
'debug_inspect',
# imported into ckan.lib.helpers
'literal',
Expand Down

0 comments on commit 6fcb736

Please sign in to comment.