本文整理汇总了Python中wagtail.wagtailcore.models.Page.DoesNotExist方法的典型用法代码示例。如果您正苦于以下问题:Python Page.DoesNotExist方法的具体用法?Python Page.DoesNotExist怎么用?Python Page.DoesNotExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.wagtailcore.models.Page
的用法示例。
在下文中一共展示了Page.DoesNotExist方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from wagtail.wagtailcore.models import Page [as 别名]
# 或者: from wagtail.wagtailcore.models.Page import DoesNotExist [as 别名]
def render(self, props):
link_type = props.get('linkType', '')
if link_type == 'page':
try:
page_id = props.get('id')
page = Page.objects.get(id=page_id)
href = page.url
except Page.DoesNotExist:
href = props.get('url', MISSING_RESOURCE_URL)
else:
href = props.get('url', MISSING_RESOURCE_URL)
anchor_properties = {
'className': 'button',
'href': href,
}
return DOM.create_element('a', anchor_properties, props['children'])
示例2: Link
# 需要导入模块: from wagtail.wagtailcore.models import Page [as 别名]
# 或者: from wagtail.wagtailcore.models.Page import DoesNotExist [as 别名]
def Link(props):
link_type = props.get('linkType', '')
title = props.get('title')
if link_type == 'page':
try:
page_id = props.get('id')
page = Page.objects.get(id=page_id)
href = page.url
except Page.DoesNotExist:
href = props.get('url', MISSING_RESOURCE_URL)
else:
href = props.get('url', MISSING_RESOURCE_URL)
anchor_properties = {
'href': href
}
if title is not None:
anchor_properties['title'] = title
return DOM.create_element('a', anchor_properties, props['children'])
示例3: Image
# 需要导入模块: from wagtail.wagtailcore.models import Page [as 别名]
# 或者: from wagtail.wagtailcore.models.Page import DoesNotExist [as 别名]
def Image(props):
"""
Inspired by:
- https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailimages/rich_text.py
- https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailimages/shortcuts.py
- https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailimages/formats.py
"""
image_model = get_image_model()
alignment = props.get('alignment', 'left')
alt_text = props.get('altText', '')
try:
image = image_model.objects.get(id=props['id'])
except image_model.DoesNotExist:
return DOM.create_element('img', {'alt': alt_text})
image_format = get_image_format(alignment)
rendition = get_rendition_or_not_found(image, image_format.filter_spec)
return DOM.create_element('img', dict(rendition.attrs_dict, **{
'class': image_format.classnames,
'src': rendition.url,
'alt': alt_text,
}))
示例4: create_from_sequence
# 需要导入模块: from wagtail.wagtailcore.models import Page [as 别名]
# 或者: from wagtail.wagtailcore.models.Page import DoesNotExist [as 别名]
def create_from_sequence(bits):
"""
Create categories from an iterable
"""
if len(bits) == 1:
# Get or create root node
name = bits[0]
try:
# Category names should be unique at the depth=2
root = Category.get_root_nodes().get(title=name)
except Category.DoesNotExist:
root = Category.add_root(title=name)
except Category.MultipleObjectsReturned:
raise ValueError((
"There are more than one categories with name "
"%s at depth=1") % name)
return [root]
else:
parents = create_from_sequence(bits[:-1])
parent, name = parents[-1], bits[-1]
try:
child = parent.get_children().get(title=name)
except (Page.DoesNotExist, Category.DoesNotExist):
child = parent.add_child(title=name)
except Category.MultipleObjectsReturned:
raise ValueError((
"There are more than one categories with name "
"%s which are children of %s") % (name, parent))
parents.append(child)
return parents
示例5: expand_db_attributes
# 需要导入模块: from wagtail.wagtailcore.models import Page [as 别名]
# 或者: from wagtail.wagtailcore.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>"
示例6: Document
# 需要导入模块: from wagtail.wagtailcore.models import Page [as 别名]
# 或者: from wagtail.wagtailcore.models.Page import DoesNotExist [as 别名]
def Document(props):
document_model = get_document_model()
try:
doc = document_model.objects.get(id=props['id'])
doc_meta = get_document_meta(doc)
except (document_model.DoesNotExist, AttributeError):
return DOM.create_element(
'a',
{'href': MISSING_RESOURCE_URL, 'class': MISSING_RESOURCE_CLASS + ' file'},
props['children']
)
icon_element = DOM.create_element(Icon, {'name': doc_meta['extension']})
metadata_element = DOM.create_element(
'span',
{'class': 'icon-text__text'},
props['children'],
' '
)
size_element = DOM.create_element(
'span',
{'class': 'file-size'},
'({ext} {size})'.format(size=doc_meta['size'], ext=doc_meta['extension'].upper())
)
link_item = DOM.create_element('a', {'href': doc.url, 'class': 'icon-text'}, icon_element, metadata_element)
return DOM.create_element('span', {'class': 'file'}, link_item, size_element)
示例7: _create
# 需要导入模块: from wagtail.wagtailcore.models import Page [as 别名]
# 或者: from wagtail.wagtailcore.models.Page import DoesNotExist [as 别名]
def _create(cls, *args, **kwargs):
try:
root = Page.objects.get(depth=0)
except Page.DoesNotExist:
root = Page.add_root(title='root')
return root.add_child(title=kwargs['title'])