當前位置: 首頁>>代碼示例>>Python>>正文


Python Page.DoesNotExist方法代碼示例

本文整理匯總了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,
        } 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:20,代碼來源:html_to_contentstate.py

示例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 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:22,代碼來源:filters.py

示例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() 
開發者ID:mozilla,項目名稱:foundation.mozilla.org,代碼行數:24,代碼來源:participate_page_featured_highlights.py

示例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>" 
開發者ID:labd,項目名稱:django-oscar-wagtail,代碼行數:13,代碼來源:edit_handlers.py

示例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>" 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:14,代碼來源:editor_html.py

示例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 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:15,代碼來源:navigation.py

示例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) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:5,代碼來源:test_page_queryset.py

示例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) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:5,代碼來源:test_page_queryset.py

示例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) 
開發者ID:mozilla,項目名稱:foundation.mozilla.org,代碼行數:40,代碼來源:bannered_campaign_page.py

示例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) 
開發者ID:mozilla,項目名稱:foundation.mozilla.org,代碼行數:12,代碼來源:initiatives_page.py

示例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) 
開發者ID:mozilla,項目名稱:foundation.mozilla.org,代碼行數:29,代碼來源:youtube_regrets_page.py

示例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) 
開發者ID:mozilla,項目名稱:foundation.mozilla.org,代碼行數:12,代碼來源:news_page.py

示例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) 
開發者ID:mozilla,項目名稱:foundation.mozilla.org,代碼行數:41,代碼來源:blog.py

示例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) 
開發者ID:mozilla,項目名稱:foundation.mozilla.org,代碼行數:12,代碼來源:styleguide.py

示例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)] 
開發者ID:mozilla,項目名稱:foundation.mozilla.org,代碼行數:36,代碼來源:opportunity.py


注:本文中的wagtail.core.models.Page.DoesNotExist方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。