本文整理匯總了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'])