本文整理汇总了Python中wagtail.core.models.Site.save方法的典型用法代码示例。如果您正苦于以下问题:Python Site.save方法的具体用法?Python Site.save怎么用?Python Site.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.core.models.Site
的用法示例。
在下文中一共展示了Site.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_duplicate_slug
# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import save [as 别名]
def test_duplicate_slug(self):
try:
from wagtail.core.models import Site
except ImportError:
from wagtail.wagtailcore.models import Site
# Create a test Site with a root page
root = models.TestRootPage(title='title', depth=1, path='0001', slug_en='slug_en', slug_de='slug_de')
root.save()
site = Site(root_page=root)
site.save()
# Add children to the root
child = root.add_child(
instance=models.TestSlugPage1(title='child1', slug_de='child', slug_en='child-en', depth=2, path='00010001')
)
child2 = root.add_child(
instance=models.TestSlugPage2(title='child2', slug_de='child-2', slug_en='child2-en', depth=2,
path='00010002')
)
# Clean should work fine as the two slugs are different
child2.clean()
# Make the slug equal to test if the duplicate is detected
child2.slug_de = 'child'
self.assertRaises(ValidationError, child2.clean)
child2.slug_de = 'child-2'
# Make the translated slug equal to test if the duplicate is detected
child2.slug_en = 'child-en'
self.assertRaises(ValidationError, child2.clean)
示例2: root_page
# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import save [as 别名]
def root_page():
"""
Get the global Wagtail root page (cleared of any subpages it might have)
:return: Root page
:rtype: wagtail.wagtailcore.models.Page
"""
try:
page = Page.objects.get(slug="root", depth=1)
except Page.DoesNotExist: # pragma: no cover
page = Page.objects.create(
title="Root",
slug='root',
content_type=ContentType.objects.get_for_model(Page),
path='0001',
depth=1,
numchild=1,
url_path='/',
)
for child in page.get_children(): # pragma: no cover
child.delete()
page.numchild = 0
page.save(update_fields=("numchild",))
site = Site.objects.first()
if not site: # pragma: no cover
site = Site()
site.root_page = page
site.is_default_site = True
site.save()
return page
示例3: test_relative_url
# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import save [as 别名]
def test_relative_url(self):
try:
from wagtail.core.models import Site
except ImportError:
from wagtail.wagtailcore.models import Site
# Create a test Site with a root page
root = models.TestRootPage(title='title slugurl', depth=1, path='0004',
slug_en='title_slugurl_en', slug_de='title_slugurl_de')
root.save()
site = Site(root_page=root)
site.save()
# Add children to the root
child = root.add_child(
instance=models.TestSlugPage1(title='child1 slugurl',
slug_en='child-slugurl-en', slug_de='child-slugurl-de',
depth=2, path='00040001')
)
child.save_revision().publish()
url_1_de = child.relative_url(site)
self.assertEqual(url_1_de, '/de/child-slugurl-de/',
'When using the default language, slugurl produces the wrong url.')
trans_real.activate('en')
url_1_en = child.relative_url(site)
self.assertEqual(url_1_en, '/en/child-slugurl-en/',
'When using non-default language, slugurl produces the wrong url.')
# Add children using non-default language
child2 = root.add_child(
instance=models.TestSlugPage2(title='child2 slugurl', title_de='child2 slugurl DE',
slug_de='child2-slugurl-de', slug_en='child2-slugurl-en',
depth=2, path='00040002')
)
child2.save_revision().publish()
url_2_en = child2.relative_url(site)
self.assertEqual(url_2_en, '/en/child2-slugurl-en/',
'When using non-default language, slugurl produces the wrong url.')
trans_real.activate('de')
url_2_de = child2.relative_url(site)
self.assertEqual(url_2_de, '/de/child2-slugurl-de/',
'When using non-default language, slugurl produces the wrong url.')