本文整理汇总了Python中wagtail.core.models.Site类的典型用法代码示例。如果您正苦于以下问题:Python Site类的具体用法?Python Site怎么用?Python Site使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Site类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_duplicate_slug
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
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