本文整理汇总了Python中cms.toolbar.toolbar.CMSToolbar.get_or_create_menu方法的典型用法代码示例。如果您正苦于以下问题:Python CMSToolbar.get_or_create_menu方法的具体用法?Python CMSToolbar.get_or_create_menu怎么用?Python CMSToolbar.get_or_create_menu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cms.toolbar.toolbar.CMSToolbar
的用法示例。
在下文中一共展示了CMSToolbar.get_or_create_menu方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_out_of_order
# 需要导入模块: from cms.toolbar.toolbar import CMSToolbar [as 别名]
# 或者: from cms.toolbar.toolbar.CMSToolbar import get_or_create_menu [as 别名]
def test_out_of_order(self):
page = create_page("toolbar-page", "nav_playground.html", "en",
published=True)
request = self.get_page_request(page, self.get_staff(), '/')
toolbar = CMSToolbar(request)
menu1 = toolbar.get_or_create_menu("test")
menu2 = toolbar.get_or_create_menu("test", "Test", side=toolbar.RIGHT, position=2)
self.assertEqual(menu1, menu2)
self.assertEqual(menu1.name, 'Test')
self.assertEqual(len(toolbar.get_right_items()), 1)
示例2: test_get_alphabetical_insert_position
# 需要导入模块: from cms.toolbar.toolbar import CMSToolbar [as 别名]
# 或者: from cms.toolbar.toolbar.CMSToolbar import get_or_create_menu [as 别名]
def test_get_alphabetical_insert_position(self):
page = create_page("toolbar-page", "nav_playground.html", "en",
published=True)
request = self.get_page_request(page, self.get_staff(), '/')
toolbar = CMSToolbar(request)
toolbar.get_left_items()
toolbar.get_right_items()
admin_menu = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, 'TestAppMenu')
# Insert alpha
alpha_position = admin_menu.get_alphabetical_insert_position('menu-alpha', SubMenu, None)
# As this will be the first item added to this, this use should return the default, or namely None
if not alpha_position:
alpha_position = admin_menu.find_first(Break, identifier=ADMINISTRATION_BREAK) + 1
admin_menu.get_or_create_menu('menu-alpha', 'menu-alpha', position=alpha_position)
# Insert gamma (should return alpha_position + 1)
gamma_position = admin_menu.get_alphabetical_insert_position('menu-gamma', SubMenu)
self.assertEqual(int(gamma_position), int(alpha_position) + 1)
admin_menu.get_or_create_menu('menu-gamma', 'menu-gamma', position=gamma_position)
# Where should beta go? It should go right where gamma is now...
beta_position = admin_menu.get_alphabetical_insert_position('menu-beta', SubMenu)
self.assertEqual(beta_position, gamma_position)
示例3: test_no_page_superuser
# 需要导入模块: from cms.toolbar.toolbar import CMSToolbar [as 别名]
# 或者: from cms.toolbar.toolbar.CMSToolbar import get_or_create_menu [as 别名]
def test_no_page_superuser(self):
request = self.get_page_request(None, self.get_superuser(), "/")
toolbar = CMSToolbar(request)
items = toolbar.get_left_items() + toolbar.get_right_items()
# Logo + edit-mode + admin-menu + logout
self.assertEqual(len(items), 3)
admin_items = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, "Test").get_items()
self.assertEqual(len(admin_items), 7, admin_items)
示例4: test_no_page_staff
# 需要导入模块: from cms.toolbar.toolbar import CMSToolbar [as 别名]
# 或者: from cms.toolbar.toolbar.CMSToolbar import get_or_create_menu [as 别名]
def test_no_page_staff(self):
request = self.get_page_request(None, self.get_staff(), '/')
toolbar = CMSToolbar(request)
toolbar.populate()
toolbar.post_template_populate()
items = toolbar.get_left_items() + toolbar.get_right_items()
# Logo + admin-menu + logout
self.assertEqual(len(items), 2, items)
admin_items = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, 'Test').get_items()
self.assertEqual(len(admin_items), 6, admin_items)
示例5: test_no_change_button
# 需要导入模块: from cms.toolbar.toolbar import CMSToolbar [as 别名]
# 或者: from cms.toolbar.toolbar.CMSToolbar import get_or_create_menu [as 别名]
def test_no_change_button(self):
page = create_page("test", "nav_playground.html", "en", published=True)
user = self.get_staff()
user.user_permissions.all().delete()
request = self.get_page_request(page, user, edit=True)
toolbar = CMSToolbar(request)
self.assertFalse(page.has_change_permission(request))
self.assertFalse(page.has_publish_permission(request))
items = toolbar.get_left_items() + toolbar.get_right_items()
# Logo + page-menu + admin-menu + logout
self.assertEqual(len(items), 3, items)
admin_items = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, "Test").get_items()
self.assertEqual(len(admin_items), 6, admin_items)
示例6: test_no_page_superuser
# 需要导入模块: from cms.toolbar.toolbar import CMSToolbar [as 别名]
# 或者: from cms.toolbar.toolbar.CMSToolbar import get_or_create_menu [as 别名]
def test_no_page_superuser(self):
request = self.get_page_request(None, self.get_superuser(), '/')
toolbar = CMSToolbar(request)
toolbar.populate()
toolbar.post_template_populate()
items = toolbar.get_left_items() + toolbar.get_right_items()
# Logo + edit-mode + admin-menu + logout
self.assertEqual(len(items), 2)
admin_items = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, 'Test').get_items()
if is_user_swapped:
self.assertEqual(len(admin_items), 6, admin_items)
else:
self.assertEqual(len(admin_items), 7, admin_items)