本文整理汇总了Python中wagtail.core.models.Page.DoesNotExist方法的典型用法代码示例。如果您正苦于以下问题:Python Page.DoesNotExist方法的具体用法?Python Page.DoesNotExist怎么用?Python Page.DoesNotExist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.core.models.Page
的用法示例。
在下文中一共展示了Page.DoesNotExist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_attribute_data
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def get_attribute_data(self, attrs):
try:
page = Page.objects.get(id=attrs['id']).specific
except Page.DoesNotExist:
# retain ID so that it's still identified as a page link (albeit a broken one)
return {
'id': int(attrs['id']),
'url': None,
'parentId': None
}
parent_page = page.get_parent()
return {
'id': page.id,
'url': page.url,
'parentId': parent_page.id if parent_page else None,
}
示例2: filter_queryset
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def filter_queryset(self, request, queryset, view):
if 'child_of' in request.GET:
try:
parent_page_id = int(request.GET['child_of'])
if parent_page_id < 0:
raise ValueError()
parent_page = view.get_base_queryset().get(id=parent_page_id)
except ValueError:
if request.GET['child_of'] == 'root':
parent_page = view.get_root_page()
else:
raise BadRequestError("child_of must be a positive integer")
except Page.DoesNotExist:
raise BadRequestError("parent page doesn't exist")
queryset = queryset.child_of(parent_page)
queryset._filtered_by_child_of = parent_page
return queryset
示例3: generate
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def generate(seed):
participate_page = None
try:
participate_page = ParticipatePage2.objects.get(title='participate')
except WagtailPage.DoesNotExist:
print('Participate page must exist. Ensure that ' +
'networkapi.wagtailpages.factory.participage_page is executing first')
reseed(seed)
print('Generating Participate Highlights')
if participate_page is not None:
featured_highlights = [HighlightFactory.create() for i in range(3)]
participate_page.featured_highlights = [
ParticipatePage2FeaturedHighlightsFactory.build(highlight=featured_highlights[i]) for i in range(3)
]
featured_highlights2 = [HighlightFactory.create() for i in range(6)]
participate_page.featured_highlights2 = [
ParticipatePage2FeaturedHighlights2Factory.build(highlight=featured_highlights2[i]) for i in range(6)
]
participate_page.save()
示例4: expand_db_attributes
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def expand_db_attributes(attrs, for_editor):
try:
page = Page.objects.get(id=attrs['id']).specific
if for_editor:
editor_attrs = 'data-linktype="page" data-id="%d" ' % page.id
else:
editor_attrs = ''
return '<a %shref="%s">' % (editor_attrs, escape(page.url))
except Page.DoesNotExist:
return "<a>"
示例5: expand_db_attributes
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def expand_db_attributes(attrs):
try:
page = Page.objects.get(id=attrs['id'])
attrs = 'data-linktype="page" data-id="%d" ' % page.id
parent_page = page.get_parent()
if parent_page:
attrs += 'data-parent-id="%d" ' % parent_page.id
return '<a %shref="%s">' % (attrs, escape(page.specific.url))
except Page.DoesNotExist:
return "<a>"
示例6: get_explorable_root_page
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def get_explorable_root_page(user):
# Get the highest common explorable ancestor for the given user. If the user
# has no permissions over any pages, this method will return None.
pages = get_pages_with_direct_explore_permission(user)
try:
root_page = pages.first_common_ancestor(
include_self=True,
strict=True
)
except Page.DoesNotExist:
root_page = None
return root_page
示例7: test_all_pages_strict
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def test_all_pages_strict(self):
with self.assertRaises(Page.DoesNotExist):
Page.objects.first_common_ancestor(strict=True)
示例8: test_empty_queryset_strict
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def test_empty_queryset_strict(self):
with self.assertRaises(Page.DoesNotExist):
Page.objects.none().first_common_ancestor(strict=True)
示例9: generate
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def generate(seed):
home_page = get_homepage()
reseed(seed)
try:
campaign_index_page = WagtailPage.objects.get(title='campaigns')
print('campaign index page exists')
except WagtailPage.DoesNotExist:
print('Generating a campaign index page')
campaign_index_page = CampaignIndexPageFactory.create(
parent=home_page,
title='campaigns',
live=True
)
reseed(seed)
print('Generating Bannered Campaign Pages under namespace')
title = 'Initial test Bannered Campaign with fixed title'
post = None
try:
post = BanneredCampaignPage.objects.get(title=title)
except BanneredCampaignPage.DoesNotExist:
post = BanneredCampaignPageFactory.create(parent=campaign_index_page, title=title)
add_tags(post)
for i in range(6):
title = Faker('sentence', nb_words=6, variable_nb_words=False)
post = None
try:
post = BanneredCampaignPage.objects.get(title=title)
except BanneredCampaignPage.DoesNotExist:
post = BanneredCampaignPageFactory.create(parent=campaign_index_page, title=title)
add_tags(post)
示例10: generate
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def generate(seed):
home_page = get_homepage()
reseed(seed)
try:
WagtailPage.objects.get(title='initiatives')
print('initiatives page exists')
except WagtailPage.DoesNotExist:
print('Generating an empty Initiatives Page')
InitiativesPageFactory.create(parent=home_page)
示例11: generate
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def generate(seed):
home_page = get_homepage()
reseed(seed)
try:
campaign_index_page = WagtailPage.objects.get(title='campaigns')
print('campaign index page exists')
except WagtailPage.DoesNotExist:
print('Generating a campaign index page')
campaign_index_page = CampaignIndexPageFactory.create(
parent=home_page,
title='campaigns',
live=True
)
reseed(seed)
title = 'YouTube Regrets'
try:
YoutubeRegretsPage.objects.get(title=title)
print('YouTube Regrets page exists')
except YoutubeRegretsPage.DoesNotExist:
print('Generating YouTube Regrets Page under campaigns namespace')
YoutubeRegretsPageFactory.create(parent=campaign_index_page, title=title)
reseed(seed)
示例12: generate
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def generate(seed):
home_page = get_homepage()
reseed(seed)
try:
WagtailPage.objects.get(title='news')
print('news page exists')
except WagtailPage.DoesNotExist:
print('Generating an empty News Page')
NewsPageFactory.create(parent=home_page)
示例13: generate
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def generate(seed):
reseed(seed)
home_page = get_homepage()
try:
blog_namespace = WagtailPage.objects.get(title='Blog')
print('blog namespace exists')
except WagtailPage.DoesNotExist:
print('Generating a blog namespace')
blog_namespace = BlogIndexPageFactory.create(
parent=home_page,
title='Blog',
header='Blog',
live=True
)
print('Generating blog posts under namespace')
title = 'Initial test blog post with fixed title'
post = None
try:
post = BlogPage.objects.get(title=title)
except BlogPage.DoesNotExist:
post = BlogPageFactory.create(parent=blog_namespace, title=title)
add_tags(post)
add_category(post)
for i in range(6):
title = Faker('sentence', nb_words=6, variable_nb_words=False)
post = None
try:
post = BlogPage.objects.get(title=title)
except BlogPage.DoesNotExist:
post = BlogPageFactory.create(parent=blog_namespace, title=title)
add_tags(post)
add_category(post)
示例14: generate
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def generate(seed):
home_page = get_homepage()
reseed(seed)
try:
WagtailPage.objects.get(title='styleguide')
print('styleguide page exists')
except WagtailPage.DoesNotExist:
print('Generating a Styleguide Page')
StyleguideFactory.create(parent=home_page)
示例15: generate
# 需要导入模块: from wagtail.core.models import Page [as 别名]
# 或者: from wagtail.core.models.Page import DoesNotExist [as 别名]
def generate(seed):
home_page = get_homepage()
reseed(seed)
try:
initiatives_page = WagtailPage.objects.get(title='initiatives')
print('initiatives page exists')
except WagtailPage.DoesNotExist:
print('Generating an empty Initiatives Page')
initiatives_page = InitiativesPageFactory.create(parent=home_page)
reseed(seed)
print('Generating Opportunity Pages as child pages of an Initiative Page')
[OpportunityPageFactory.create(parent=initiatives_page) for i in range(3)]
reseed(seed)
try:
OpportunityPage.objects.get(title='single-page-opportunity')
print('single-page OpportunityPage exists')
except OpportunityPage.DoesNotExist:
print('Generating single-page OpportunityPage')
OpportunityPageFactory.create(parent=initiatives_page, title='single-page-opportunity')
reseed(seed)
try:
OpportunityPage.objects.get(title='multi-page-opportunity')
print('multi-page OpportunityPage exists')
except OpportunityPage.DoesNotExist:
print('Generating multi-page OpportunityPage')
multi_page_opportunity = OpportunityPageFactory(parent=initiatives_page, title='multi-page-opportunity')
[OpportunityPageFactory(parent=multi_page_opportunity) for k in range(3)]