コード例 #1
0
 def test_invalid_reverse_in_node_renders_empty_menu(self):
     menu_pool.register_menu(InvalidURLMenu)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu %}")
     tpl.render(context)
     nodes = context['nodes']
     self.assertEqual(len(nodes), 0)
コード例 #2
0
 def setUp(self):
     menu_pool.discovered = False
     self.old_menu = menu_pool.menus
     menu_pool.menus = {}
     menu_pool.discover_menus()
     menu_pool.register_menu(StaticMenu)
     menu_pool.register_menu(StaticMenu2)
コード例 #3
0
 def test_menu_for_anonymous(self):
     menu_pool.register_menu(StaticMenu)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu %}")
     tpl.render(context)
     nodes = context['nodes']
     self.assertEqual(len(nodes), 2)
     self.assertEqual(nodes[0].title, 'B')
     self.assertEqual(nodes[1].title, 'C')
コード例 #4
0
 def test_menu_for_authenticated(self):
     menu_pool.register_menu(StaticMenu)
     user = self.create_user()
     context = self.get_context(user=user)
     tpl = Template("{% load menu_tags %}{% show_menu %}")
     tpl.render(context)
     nodes = context['nodes']
     self.assertEqual(len(nodes), 2)
     self.assertEqual(nodes[0].title, 'A')
     self.assertEqual(nodes[1].title, 'C')
コード例 #5
0
 def test_node_visibility(self):
     menu_pool.register_menu(VisibilityMenu)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu %}")
     tpl.render(context)
     nodes = context['nodes']
     self.assertEqual(len(nodes), 4)
     self.assertEqual(nodes[0].title, 'A')
     self.assertEqual(nodes[1].title, 'B')
     self.assertEqual(nodes[2].title, 'C')
     self.assertEqual(nodes[3].title, 'F')
コード例 #6
0
 def test_menu_from_single_namespace(self):
     menu_pool.register_menu(StaticMenu)
     menu_pool.register_menu(StaticMenu2)
     context = self.get_context()
     tpl = Template('{% load menu_tags %}{% show_menu "workmate/menu/menu.html" "StaticMenu" %}')
     tpl.render(context)
     nodes = context['nodes']
     self.assertEqual(nodes[0].title, 'A')
     self.assertEqual(nodes[1].title, 'B')
     self.assertEqual(nodes[2].title, 'C')
     self.assertEqual(nodes[3].title, 'D')
     self.assertEqual(nodes[4].title, 'E')
コード例 #7
0
 def test_menu_nodes_from_multiple_menus(self):
     menu_pool.register_menu(StaticMenu)
     menu_pool.register_menu(StaticMenu2)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu %}")
     tpl.render(context)
     nodes = context['nodes']
     self.assertEqual(nodes[0].title, 'A')
     self.assertEqual(nodes[1].title, 'B')
     self.assertEqual(nodes[2].title, 'C')
     self.assertEqual(nodes[3].title, 'D')
     self.assertEqual(nodes[4].title, 'E')
     self.assertEqual(nodes[5].title, 'F')
コード例 #8
0
 def test_appending_nodes_to_existing_namespace(self):
     menu_pool.register_menu(StaticMenu)
     menu_pool.register_menu(StaticExtendedMenu)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu %}")
     tpl.render(context)
     nodes = context['nodes']
     self.assertEqual(nodes[0].title, 'A')
     self.assertEqual(nodes[1].title, 'B')
     self.assertEqual(nodes[2].title, 'C')
     self.assertEqual(nodes[2].menu_title, 'Static Menu')
     self.assertEqual(nodes[3].title, 'C EX')
     # ensure the appended node has the correct title
     self.assertEqual(nodes[3].menu_title, 'Static Menu')
     self.assertEqual(nodes[4].title, 'D')
     self.assertEqual(nodes[5].title, 'E')
     self.assertEqual(nodes[6].title, 'F')
コード例 #9
0
 def test_menu_nodes(self):
     menu_pool.register_menu(StaticMenu)
     context = self.get_context()
     tpl = Template("{% load menu_tags %}{% show_menu %}")
     tpl.render(context)
     nodes = context['nodes']
     self.assertEqual(nodes[0].title, 'A')
     self.assertEqual(nodes[0].get_absolute_url(), '/A/')
     self.assertEqual(nodes[0].menu_title, 'Static Menu')
     self.assertEqual(nodes[1].title, 'B')
     self.assertEqual(nodes[1].get_absolute_url(), '/B/')
     self.assertEqual(nodes[1].menu_title, 'Static Menu')
     self.assertEqual(nodes[2].title, 'C')
     self.assertEqual(nodes[2].get_absolute_url(), '/C/')
     self.assertEqual(nodes[2].menu_title, 'Static Menu')
     self.assertEqual(nodes[3].title, 'D')
     self.assertEqual(nodes[3].get_absolute_url(), '/D/')
     self.assertEqual(nodes[3].menu_title, 'Static Menu')
     self.assertEqual(nodes[4].title, 'E')
     self.assertEqual(nodes[4].get_absolute_url(), '/E/')
     self.assertEqual(nodes[4].menu_title, 'Static Menu')
コード例 #10
0
# -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _

from workmate.menus.base import Menu, NavigationNode
from workmate.menus.menu_pool import menu_pool


class WorkmatePluginMenu(Menu):

    title = _('Plugins')

    def get_nodes(self, request):
        node1 = NavigationNode(_('Example Plugin'), '/', 1, icon='plug')
        nodes = [node1]
        return nodes


menu_pool.register_menu(WorkmatePluginMenu)
コード例 #11
0
        node1 = NavigationNode(_('Home'), '/', 1, icon='home', sort_order=1)
        node2 = NavigationNode(_('Agile'),
                               reverse('agile-index'),
                               2,
                               icon='repeat',
                               sort_order=2)
        node3 = NavigationNode(_('Contacts'),
                               reverse('contact-list'),
                               2,
                               icon='users',
                               sort_order=3)
        nodes = [node1, node2, node3]
        return nodes


menu_pool.register_menu(MainMenu)


class AdminMenu(Menu):

    title = _('Administration')
    sort_order = 99

    def get_nodes(self, request):
        node1 = NavigationNode(_('Site Administration'),
                               reverse('admin:index'),
                               1,
                               icon='cogs',
                               attr={'staff_only': True})
        nodes = [node1]
        return nodes
コード例 #12
0
from workmate.menus.menu_pool import menu_pool


class MainMenu(Menu):

    title = _('Main Menu')
    sort_order = -1

    def get_nodes(self, request):
        node1 = NavigationNode(_('Home'), '/', 1, icon='home', sort_order=1)
        node2 = NavigationNode(_('Contacts'), reverse('contact-list'), 2, icon='users', sort_order=2)
        nodes = [node1, node2]
        return nodes


menu_pool.register_menu(MainMenu)


class AdminMenu(Menu):

    title = _('Administration')
    sort_order = 99

    def get_nodes(self, request):
        node1 = NavigationNode(_('Site Administration'), reverse('admin:index'), 1, icon='cogs',
                               attr={'staff_only': True})
        nodes = [node1]
        return nodes


menu_pool.register_menu(AdminMenu)
コード例 #13
0
 def test_duplicate_menu_class_raises_exception(self):
     with self.assertRaises(NamespaceAlreadyRegistered):
         menu_pool.register_menu(StaticMenu)
         menu_pool._expand_menus()
コード例 #14
0
 def test_invalid_menu_class_raises_exception(self):
     with self.assertRaises(AssertionError):
         menu_pool.register_menu(InvalidMenuClass)