本文整理汇总了Python中cms.api.create_page方法的典型用法代码示例。如果您正苦于以下问题:Python api.create_page方法的具体用法?Python api.create_page怎么用?Python api.create_page使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cms.api
的用法示例。
在下文中一共展示了api.create_page方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_plugin_loading_queries
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_plugin_loading_queries(self):
with self.settings(CMS_TEMPLATES=(('placeholder_tests/base.html', 'tpl'),)):
page = create_page('home', 'placeholder_tests/base.html', 'en', published=True, slug='home')
placeholders = list(page.placeholders.all())
for i, placeholder in enumerate(placeholders):
for j in range(5):
add_plugin(placeholder, TextPlugin, 'en', body='text-%d-%d' % (i, j))
add_plugin(placeholder, LinkPlugin, 'en', name='link-%d-%d' % (i, j))
# trigger the apphook query so that it doesn't get in our way
reverse('pages-root')
# trigger the get_languages query so it doesn't get in our way
context = self.get_context(page=page)
context['request'].current_page.get_languages()
with self.assertNumQueries(4):
for i, placeholder in enumerate(placeholders):
content = get_placeholder_content(context, context['request'], page, placeholder.slot, False, None)
for j in range(5):
self.assertIn('text-%d-%d' % (i, j), content)
self.assertIn('link-%d-%d' % (i, j), content)
示例2: test_plugin_breadcrumbs
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_plugin_breadcrumbs(self):
"""
Test the plugin breadcrumbs order
"""
draft_page = api.create_page("home", "col_two.html", "en",
slug="page1", published=False, in_navigation=True)
placeholder = draft_page.placeholders.get(slot="col_left")
columns = api.add_plugin(placeholder, "MultiColumnPlugin", "en")
column = api.add_plugin(placeholder, "ColumnPlugin", "en", target=columns, width='10%')
text_plugin = api.add_plugin(placeholder, "TextPlugin", "en", target=column, body="I'm the second")
text_breadcrumbs = text_plugin.get_breadcrumb()
self.assertEqual(len(columns.get_breadcrumb()), 1)
self.assertEqual(len(column.get_breadcrumb()), 2)
self.assertEqual(len(text_breadcrumbs), 3)
self.assertTrue(text_breadcrumbs[0]['title'], columns.get_plugin_class().name)
self.assertTrue(text_breadcrumbs[1]['title'], column.get_plugin_class().name)
self.assertTrue(text_breadcrumbs[2]['title'], text_plugin.get_plugin_class().name)
self.assertTrue('/edit-plugin/%s/'% columns.pk in text_breadcrumbs[0]['url'])
self.assertTrue('/edit-plugin/%s/'% column.pk, text_breadcrumbs[1]['url'])
self.assertTrue('/edit-plugin/%s/'% text_plugin.pk, text_breadcrumbs[2]['url'])
示例3: test_inherit_plugin_with_empty_plugin
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_inherit_plugin_with_empty_plugin(self):
inheritfrompage = api.create_page('page to inherit from',
'nav_playground.html',
'en', published=True)
body = inheritfrompage.placeholders.get(slot="body")
empty_plugin = CMSPlugin(
plugin_type='TextPlugin', # create an empty plugin
placeholder=body,
position=1,
language='en',
)
empty_plugin.add_root(instance=empty_plugin)
other_page = api.create_page('other page', 'nav_playground.html', 'en', published=True)
inherited_body = other_page.placeholders.get(slot="body")
api.add_plugin(inherited_body, InheritPagePlaceholderPlugin, 'en', position='last-child',
from_page=inheritfrompage, from_language='en')
api.add_plugin(inherited_body, "TextPlugin", "en", body="foobar")
# this should not fail, even if there in an empty plugin
rendered = inherited_body.render(context=self.get_context(other_page.get_absolute_url(), page=other_page), width=200)
self.assertIn("foobar", rendered)
示例4: test_plugin_child_classes_from_settings
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_plugin_child_classes_from_settings(self):
page = api.create_page("page", "nav_playground.html", "en", published=True)
placeholder = page.placeholders.get(slot='body')
ChildClassesPlugin = type('ChildClassesPlugin', (CMSPluginBase,),
dict(child_classes=['TextPlugin'], render_template='allow_children_plugin.html'))
plugin_pool.register_plugin(ChildClassesPlugin)
plugin = api.add_plugin(placeholder, ChildClassesPlugin, settings.LANGUAGES[0][0])
plugin = plugin.get_plugin_class_instance()
## assert baseline
self.assertEqual(['TextPlugin'], plugin.get_child_classes(placeholder.slot, page))
CMS_PLACEHOLDER_CONF = {
'body': {
'child_classes': {
'ChildClassesPlugin': ['LinkPlugin', 'PicturePlugin'],
}
}
}
with self.settings(CMS_PLACEHOLDER_CONF=CMS_PLACEHOLDER_CONF):
self.assertEqual(['LinkPlugin', 'PicturePlugin'],
plugin.get_child_classes(placeholder.slot, page))
plugin_pool.unregister_plugin(ChildClassesPlugin)
示例5: create_fixtures
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def create_fixtures(self):
"""
Tree from fixture:
page1
page2
page3
page4
page5
"""
defaults = {
'template': 'nav_playground.html',
'language': 'en',
}
with self.settings(CMS_PERMISSION=False):
p1 = create_page('page1', published=True, in_navigation=True, **defaults)
p4 = create_page('page4', published=True, in_navigation=True, **defaults)
p1 = Page.objects.get(pk=p1.pk)
p2 = create_page('page2', published=True, in_navigation=True, parent=p1, **defaults)
create_page('page3', published=True, in_navigation=True, parent=p2, **defaults)
p4 = Page.objects.get(pk=p4.pk)
create_page('page5', published=True, in_navigation=True, parent=p4, **defaults)
示例6: test_absolute_url
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_absolute_url(self):
user = self.get_superuser()
page = create_page("page", "nav_playground.html", "en", published=True)
create_title("fr", "french home", page)
page_2 = create_page("inner", "nav_playground.html", "en", published=True, parent=page)
create_title("fr", "french inner", page_2)
publish_page(page_2, user, "fr")
self.assertEqual(page_2.get_absolute_url(), '/en/inner/')
self.assertEqual(page_2.get_absolute_url(language='en'), '/en/inner/')
self.assertEqual(page_2.get_absolute_url(language='fr'), '/fr/french-inner/')
with force_language('fr'):
self.assertEqual(page_2.get_absolute_url(), '/fr/french-inner/')
self.assertEqual(page_2.get_absolute_url(language='en'), '/en/inner/')
self.assertEqual(page_2.get_absolute_url(language='fr'), '/fr/french-inner/')
示例7: test_create_page_api_with_long_username
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_create_page_api_with_long_username(self):
page_data = {
'title': 'root',
'slug': 'root',
'language': settings.LANGUAGES[0][0],
'template': 'nav_playground.html',
'created_by': self._create_user(
'V' * constants.PAGE_USERNAME_MAX_LENGTH + 'ERY-LONG-USERNAME',
is_staff=True,
is_superuser=True,
),
}
page = create_page(**page_data)
self.assertEqual(Page.objects.count(), 1)
self.assertLessEqual(len(page.created_by), constants.PAGE_USERNAME_MAX_LENGTH)
self.assertRegexpMatches(page.created_by, r'V+\.{3} \(id=\d+\)')
self.assertLessEqual(len(page.changed_by), constants.PAGE_USERNAME_MAX_LENGTH)
self.assertRegexpMatches(page.changed_by, r'V+\.{3} \(id=\d+\)')
self.assertEqual(list(Title.objects.drafts().values_list('path', flat=True)), [u''])
示例8: test_delete_page_no_template
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_delete_page_no_template(self):
page_data = {
'title': 'root',
'slug': 'root',
'language': settings.LANGUAGES[0][0],
'template': 'nav_playground.html',
}
page = create_page(**page_data)
page.template = 'no_such_template.html'
signals.pre_save.disconnect(pre_save_page, sender=Page, dispatch_uid='cms_pre_save_page')
signals.post_save.disconnect(post_save_page, sender=Page, dispatch_uid='cms_post_save_page')
page.save(no_signals=True)
signals.pre_save.connect(pre_save_page, sender=Page, dispatch_uid='cms_pre_save_page')
signals.post_save.connect(post_save_page, sender=Page, dispatch_uid='cms_post_save_page')
page.delete()
self.assertEqual(Page.objects.count(), 0)
示例9: test_slug_collisions_api_3
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_slug_collisions_api_3(self):
""" Checks for slug collisions on children of a non root page - uses API to create pages
"""
page1 = create_page('test page 1', 'nav_playground.html', 'en',
published=True)
page1_1 = create_page('test page 1_1', 'nav_playground.html', 'en',
published=True, parent=page1, slug="foo")
page1_1_1 = create_page('test page 1_1_1', 'nav_playground.html', 'en',
published=True, parent=page1_1, slug="bar")
page1_1_2 = create_page('test page 1_1_1', 'nav_playground.html', 'en',
published=True, parent=page1_1, slug="bar")
page1_2 = create_page('test page 1_2', 'nav_playground.html', 'en',
published=True, parent=page1, slug="bar")
# Direct children of home has different slug so it's ok.
self.assertTrue(is_valid_page_slug(page1_1, page1_1.parent, "en", page1_1.get_slug("en"), page1_1.site))
self.assertTrue(is_valid_page_slug(page1_2, page1_2.parent, "en", page1_2.get_slug("en"), page1_2.site))
# children of page1_1 has the same slug -> you lose!
self.assertFalse(
is_valid_page_slug(page1_1_1, page1_1_1.parent, "en", page1_1_1.get_slug("en"), page1_1_1.site))
self.assertFalse(
is_valid_page_slug(page1_1_2, page1_1_2.parent, "en", page1_1_2.get_slug("en"), page1_1_2.site))
示例10: test_details_view
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_details_view(self):
"""
Test the details view
"""
superuser = self.get_superuser()
self.assertEqual(Page.objects.all().count(), 0)
with self.login_user_context(superuser):
response = self.client.get(self.get_pages_root())
self.assertEqual(response.status_code, 404)
page = create_page('test page 1', "nav_playground.html", "en")
page.publish('en')
response = self.client.get(self.get_pages_root())
self.assertEqual(response.status_code, 200)
self.assertTrue(page.publish('en'))
page2 = create_page("test page 2", "nav_playground.html", "en",
parent=page, published=True)
homepage = Page.objects.get_home()
self.assertTrue(homepage.get_slug(), 'test-page-1')
self.assertEqual(page2.get_absolute_url(), '/en/test-page-2/')
response = self.client.get(page2.get_absolute_url())
self.assertEqual(response.status_code, 200)
示例11: test_copy_page
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_copy_page(self):
"""
Test that a page can be copied via the admin
"""
page_a = create_page("page_a", "nav_playground.html", "en", published=True)
page_a_a = create_page("page_a_a", "nav_playground.html", "en",
parent=page_a, published=True, reverse_id="hello")
create_page("page_a_a_a", "nav_playground.html", "en", parent=page_a_a, published=True)
page_b = create_page("page_b", "nav_playground.html", "en", published=True)
page_b_a = create_page("page_b_b", "nav_playground.html", "en",
parent=page_b, published=True)
count = Page.objects.drafts().count()
superuser = self.get_superuser()
with self.login_user_context(superuser):
self.copy_page(page_a, page_b_a)
self.assertEqual(Page.objects.drafts().count() - count, 3)
示例12: test_copy_page_method
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_copy_page_method(self):
"""
Test that a page can be copied via the admin
"""
page_a = create_page("page_a", "nav_playground.html", "en", published=False)
page_a_a = create_page("page_a_a", "nav_playground.html", "en",
parent=page_a, published=False, reverse_id="hello")
create_page("page_a_a_a", "nav_playground.html", "en", parent=page_a_a, published=False)
site = Site.objects.create(domain='whatever.com', name='whatever')
pages = Page.objects.drafts().filter(site_id=1, depth=1)
with transaction.atomic():
for page in pages:
page.copy_page(None, site)
with transaction.atomic():
for page in pages:
page.copy_page(None, site)
self.assertEqual(Page.objects.filter(site_id=1, depth=1).count(), 1)
self.assertEqual(Page.objects.filter(site_id=1).count(), 3)
self.assertEqual(Page.objects.filter(site_id=site.pk, depth=1).count(), 2)
self.assertEqual(Page.objects.filter(site_id=site.pk).count(), 6)
示例13: test_ancestor_expired
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_ancestor_expired(self):
yesterday = tz_now() - datetime.timedelta(days=1)
tomorrow = tz_now() + datetime.timedelta(days=1)
root = create_page("root", "nav_playground.html", "en", slug="root",
published=True)
page_past = create_page("past", "nav_playground.html", "en", slug="past",
publication_end_date=yesterday,
published=True, parent=root)
page_test = create_page("test", "nav_playground.html", "en", slug="test",
published=True, parent=page_past)
page_future = create_page("future", "nav_playground.html", "en", slug="future",
publication_date=tomorrow,
published=True, parent=root)
page_test_2 = create_page("test", "nav_playground.html", "en", slug="test",
published=True, parent=page_future)
request = self.get_request(page_test.get_absolute_url())
page = get_page_from_request(request)
self.assertEqual(page, None)
request = self.get_request(page_test_2.get_absolute_url())
page = get_page_from_request(request)
self.assertEqual(page, None)
示例14: test_public_home_page_replaced
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_public_home_page_replaced(self):
"""Test that publishing changes to the home page doesn't move the public version"""
home = create_page('home', 'nav_playground.html', 'en', published=True, slug='home')
self.assertEqual(Page.objects.drafts().get_home().get_slug(), 'home')
home.publish('en')
self.assertEqual(Page.objects.public().get_home().get_slug(), 'home')
other = create_page('other', 'nav_playground.html', 'en', published=True, slug='other')
other.publish('en')
self.assertEqual(Page.objects.drafts().get_home(), home)
self.assertEqual(Page.objects.drafts().get_home().get_slug(), 'home')
self.assertEqual(Page.objects.public().get_home().get_slug(), 'home')
home = Page.objects.get(pk=home.id)
home.in_navigation = True
home.save()
home.publish('en')
self.assertEqual(Page.objects.drafts().get_home().get_slug(), 'home')
self.assertEqual(Page.objects.public().get_home().get_slug(), 'home')
示例15: test_rename_node
# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import create_page [as 别名]
def test_rename_node(self):
home = create_page('grandpa', 'nav_playground.html', 'en', slug='home', published=True)
home.publish('en')
parent = create_page('parent', 'nav_playground.html', 'en', slug='parent', published=True)
parent.publish('en')
child = create_page('child', 'nav_playground.html', 'en', slug='child', published=True, parent=parent)
child.publish('en')
page_title = Title.objects.get(page=parent)
page_title.slug = "father"
page_title.save()
parent = Page.objects.get(pk=parent.pk)
parent.publish('en')
child = Page.objects.get(pk=child.pk)
self.assertEqual(child.get_absolute_url(language='en'), '/en/father/child/')
self.assertEqual(child.publisher_public.get_absolute_url(language='en'), '/en/father/child/')