menu.py 983 B

1234567891011121314151617181920212223242526272829
  1. from menus.base import Menu, NavigationNode, Modifier
  2. from menus.menu_pool import menu_pool
  3. from django.utils.translation import ugettext_lazy as _
  4. from django.core.urlresolvers import reverse
  5. class CoreMenu(Menu):
  6. def get_nodes(self, request):
  7. nodes = []
  8. compare = NavigationNode(_('compare'), reverse('compare'), 1, attr={'priority':1002})
  9. candidates = NavigationNode(_('candidates'), reverse('candidates'), 2, attr={'priority':1001})
  10. partners = NavigationNode(_('partners'), reverse('partners'), 2, attr={'priority':1003})
  11. nodes.append(candidates)
  12. nodes.append(compare)
  13. nodes.append(partners)
  14. return nodes
  15. class CoreModifier(Modifier):
  16. def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
  17. return sorted(
  18. nodes,
  19. key=lambda n: n.attr.get('priority', 1000)
  20. )
  21. menu_pool.register_menu(CoreMenu)
  22. menu_pool.register_modifier(CoreModifier)