本文整理汇总了Python中cms.toolbar.toolbar.CMSToolbar类的典型用法代码示例。如果您正苦于以下问题:Python CMSToolbar类的具体用法?Python CMSToolbar怎么用?Python CMSToolbar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CMSToolbar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_publish_button
def test_publish_button(self):
page = create_page("test", "nav_playground.html", "en", published=True)
request = self.get_page_request(page, self.get_superuser(), edit=True)
toolbar = CMSToolbar(request)
self.assertTrue(toolbar.edit_mode)
items = toolbar.get_left_items() + toolbar.get_right_items()
self.assertEqual(len(items), 7)
示例2: test_template_change_permission
def test_template_change_permission(self):
with SettingsOverride(CMS_PERMISSIONS=True):
page = create_page("test", "nav_playground.html", "en", published=True)
request = self.get_page_request(page, self.get_nonstaff())
toolbar = CMSToolbar(request)
items = toolbar.get_left_items() + toolbar.get_right_items()
self.assertEqual([item for item in items if item.css_class_suffix == "templates"], [])
示例3: test_anon
def test_anon(self):
page = create_page("test", "nav_playground.html", "en")
request = self.get_page_request(page, self.get_anon())
toolbar = CMSToolbar(request)
items = toolbar.get_left_items() + toolbar.get_right_items()
self.assertEqual(len(items), 0)
示例4: test_toolbar_with_an_existing_usersetting
def test_toolbar_with_an_existing_usersetting(self):
"""
Test that UserSettings toolbar item URL is for change_view for superuser
if UserSettings already exists for current site
"""
usersettings_model_opts = self.UserSettings._meta
usersettings_obj = self.UserSettings.objects.create(**self.usersettings_data)
from cms.toolbar.toolbar import CMSToolbar
page = self.get_pages()
request = self.get_page_request(page, self.user, '/', edit=True)
toolbar = CMSToolbar(request)
toolbar.get_left_items()
admin_menu = toolbar.menus[ADMIN_MENU_IDENTIFIER]
MENU_ITEM_TITLE = usersettings_model_opts.verbose_name
change_url = '%s?%s' % (
reverse('admin:%s_%s_change' % (
usersettings_model_opts.app_label,
usersettings_model_opts.module_name), args=(usersettings_obj.pk,)),
IS_POPUP_VAR)
usersettings_menu = \
admin_menu.find_items(ModalItem, name='%s ...' % force_unicode(MENU_ITEM_TITLE))
self.assertEqual(change_url, usersettings_menu[0].item.url)
示例5: test_toolbar_with_items
def test_toolbar_with_items(self):
"""
Test that PageTags/TitleTags items are present for superuser if PageTags/TitleTags exists for current page
"""
from cms.toolbar.toolbar import CMSToolbar
page1, page2 = self.get_pages()
page_ext = PageTags.objects.create(extended_object=page1)
title_tags = TitleTags.objects.create(extended_object=page1.get_title_obj('en'))
request = self.get_page_request(page1, self.user, '/', edit=True)
toolbar = CMSToolbar(request)
toolbar.get_left_items()
page_menu = toolbar.find_items(Menu, name='Page')[0].item
tags_menu = page_menu.find_items(SubMenu, name=force_text(PAGE_TAGS_MENU_TITLE))[0].item
pagetags_menu = tags_menu.find_items(ModalItem, name="{0}...".format(force_text(PAGE_TAGS_ITEM_TITLE)))
self.assertEqual(len(pagetags_menu), 1)
self.assertEqual(len(pagetags_menu), 1)
self.assertTrue(pagetags_menu[0].item.url.startswith(reverse('admin:djangocms_page_tags_pagetags_change', args=(page_ext.pk,))))
url_change = False
url_add = False
for title in page1.title_set.all():
language = get_language_object(title.language)
titletags_menu = tags_menu.find_items(ModalItem, name='{0}...'.format(language['name']))
self.assertEqual(len(titletags_menu), 1)
try:
title_ext = TitleTags.objects.get(extended_object_id=title.pk)
self.assertEqual(title_ext, title_tags)
self.assertTrue(titletags_menu[0].item.url.startswith(reverse('admin:djangocms_page_tags_titletags_change', args=(title_ext.pk,))))
url_change = True
except TitleTags.DoesNotExist:
self.assertTrue(titletags_menu[0].item.url.startswith(reverse('admin:djangocms_page_tags_titletags_add')))
url_add = True
self.assertTrue(url_change and url_add)
示例6: test_toolbar_with_items
def test_toolbar_with_items(self):
"""
Test that PageMeta/TitleMeta items are present for superuser if PageMeta/TitleMeta exists for current page
"""
from cms.toolbar.toolbar import CMSToolbar
page1, page2 = self.get_pages()
page_ext = PageMeta.objects.create(extended_object=page1)
request = self.get_page_request(page1, self.user, '/', edit=True)
toolbar = CMSToolbar(request)
toolbar.get_left_items()
page_menu = toolbar.menus['page']
meta_menu = page_menu.find_items(SubMenu, name=force_text(PAGE_META_MENU_TITLE))[0].item
try:
pagemeta_menu = meta_menu.find_items(ModalItem, name="{0}...".format(force_text(PAGE_META_ITEM_TITLE)))
self.assertEqual(len(pagemeta_menu), 1)
except AssertionError:
pagemeta_menu = meta_menu.find_items(ModalItem, name="{0} ...".format(force_text(PAGE_META_ITEM_TITLE)))
self.assertEqual(len(pagemeta_menu), 1)
self.assertTrue(pagemeta_menu[0].item.url.startswith(reverse('admin:djangocms_page_meta_pagemeta_change', args=(page_ext.pk,))))
for title in page1.title_set.all():
language = get_language_object(title.language)
try:
titlemeta_menu = meta_menu.find_items(ModalItem, name='{0}...'.format(language['name']))
self.assertEqual(len(titlemeta_menu), 1)
except AssertionError:
titlemeta_menu = meta_menu.find_items(ModalItem, name='{0} ...'.format(language['name']))
self.assertEqual(len(titlemeta_menu), 1)
try:
title_ext = TitleMeta.objects.get(extended_object_id=title.pk)
self.assertTrue(titlemeta_menu[0].item.url.startswith(reverse('admin:djangocms_page_meta_titlemeta_change', args=(title_ext.pk,))))
except TitleMeta.DoesNotExist:
self.assertTrue(titlemeta_menu[0].item.url.startswith(reverse('admin:djangocms_page_meta_titlemeta_add')))
示例7: test_nonstaff
def test_nonstaff(self):
page = create_page("test", "nav_playground.html", "en", published=True)
request = self.get_page_request(page, self.get_nonstaff())
toolbar = CMSToolbar(request)
items = toolbar.get_left_items() + toolbar.get_right_items()
# Logo + edit-mode + logout
self.assertEqual(len(items), 0)
示例8: test_toolbar
def test_toolbar(self):
"""
Test that PageMeta/TitleMeta items are present for superuser
"""
from cms.toolbar.toolbar import CMSToolbar
NEW_CMS_LANGS = {
1: [
{
'code': 'en',
'name': 'English',
'public': True,
},
{
'code': 'it',
'name': 'Italiano',
'public': True,
},
],
'default': {
'hide_untranslated': False,
},
}
page1, page2 = self.get_pages()
with self.settings(CMS_LANGUAGES=NEW_CMS_LANGS):
request = self.get_page_request(page1, self.user, '/', edit=True)
toolbar = CMSToolbar(request)
toolbar.get_left_items()
page_menu = toolbar.menus['page']
meta_menu = page_menu.find_items(SubMenu, name=force_text(PAGE_META_MENU_TITLE))[0].item
try:
self.assertEqual(len(meta_menu.find_items(ModalItem, name="{0}...".format(force_text(PAGE_META_ITEM_TITLE)))), 1)
except AssertionError:
self.assertEqual(len(meta_menu.find_items(ModalItem, name="{0} ...".format(force_text(PAGE_META_ITEM_TITLE)))), 1)
self.assertEqual(len(meta_menu.find_items(ModalItem)), len(NEW_CMS_LANGS[1])+1)
示例9: test_not_is_staff
def test_not_is_staff(self):
request = RequestFactory().get("/en/?edit")
request.session = {}
request.LANGUAGE_CODE = "en"
request.user = AnonymousUser()
toolbar = CMSToolbar(request)
self.assertEqual(len(toolbar.get_left_items()), 0)
self.assertEqual(len(toolbar.get_right_items()), 0)
示例10: test_no_page_superuser
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)
示例11: test_no_page
def test_no_page(self):
"""
Test that no page menu is present if request not in a page
"""
from cms.toolbar.toolbar import CMSToolbar
request = self.get_page_request(None, self.user, '/', edit=True)
toolbar = CMSToolbar(request)
toolbar.get_left_items()
page_menu = toolbar.find_items(Menu, name='Page')
self.assertEqual(page_menu, [])
示例12: test_toolbar_no_locale
def test_toolbar_no_locale(self):
page = create_page('test', 'nav_playground.html', 'en-us', published=True)
sub = create_page('sub', 'nav_playground.html', 'en-us', published=True, parent=page)
# loads the urlconf before reverse below
sub.get_absolute_url('en-us')
request = self.get_page_request(sub, self.get_superuser(), edit=True)
del request.LANGUAGE_CODE
toolbar = CMSToolbar(request)
toolbar.set_object(sub)
self.assertEqual(toolbar.get_object_public_url(), '/sub/')
示例13: test_no_publish_button
def test_no_publish_button(self):
page = create_page("test", "nav_playground.html", "en", published=True)
request = self.get_page_request(page, self.get_staff(), edit=True)
toolbar = CMSToolbar(request)
self.assertTrue(page.has_change_permission(request))
self.assertFalse(page.has_publish_permission(request))
self.assertTrue(toolbar.edit_mode)
items = toolbar.get_left_items() + toolbar.get_right_items()
# Logo + edit-mode + templates + page-menu + admin-menu + logout
self.assertEqual(len(items), 6)
示例14: test_toolbar
def test_toolbar(self):
"""
Test that PageSitemapProperties item is present for superuser
"""
from cms.toolbar.toolbar import CMSToolbar
page1, page2 = self.get_pages()
request = self.get_page_request(page1, self.user, '/', edit=True)
toolbar = CMSToolbar(request)
toolbar.get_left_items()
page_menu = toolbar.menus['page']
self.assertEqual(len(page_menu.find_items(ModalItem, name="%s ..." % force_text(PAGE_SITEMAP_MENU_TITLE))), 1)
示例15: test_out_of_order
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)