Python wagtail.core.models.Page.DoesNotExist() Examples
The following are 22
code examples of wagtail.core.models.Page.DoesNotExist().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
wagtail.core.models.Page
, or try the search function
.
Example #1
Source File: html_to_contentstate.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
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, }
Example #2
Source File: filters.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #3
Source File: filters.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
def filter_queryset(self, request, queryset, view): if 'descendant_of' in request.GET: if hasattr(queryset, '_filtered_by_child_of'): raise BadRequestError("filtering by descendant_of with child_of is not supported") try: parent_page_id = int(request.GET['descendant_of']) if parent_page_id < 0: raise ValueError() parent_page = view.get_base_queryset().get(id=parent_page_id) except ValueError: if request.GET['descendant_of'] == 'root': parent_page = view.get_root_page() else: raise BadRequestError("descendant_of must be a positive integer") except Page.DoesNotExist: raise BadRequestError("ancestor page doesn't exist") queryset = queryset.descendant_of(parent_page) return queryset
Example #4
Source File: participate_page_featured_highlights.py From foundation.mozilla.org with Mozilla Public License 2.0 | 6 votes |
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()
Example #5
Source File: news_page.py From foundation.mozilla.org with Mozilla Public License 2.0 | 5 votes |
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)
Example #6
Source File: utils.py From donate-wagtail with Mozilla Public License 2.0 | 5 votes |
def is_donation_page(page_id): from .models import CampaignPage, LandingPage # Avoid circular import try: page = Page.objects.live().get(pk=page_id).specific except Page.DoesNotExist: return False return page.__class__ in [CampaignPage, LandingPage]
Example #7
Source File: views.py From hypha with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_queryset(self): # We want to only show lab or Rounds in this view, their base class is Page try: self.obj = Page.objects.get(pk=self.kwargs.get('pk')).specific except Page.DoesNotExist: raise Http404(_("No Round or Lab found matching the query")) if not isinstance(self.obj, (LabBase, RoundBase)): raise Http404(_("No Round or Lab found matching the query")) return super().get_queryset().filter(Q(round=self.obj) | Q(page=self.obj))
Example #8
Source File: utils.py From wagtail-torchbox with MIT License | 5 votes |
def serialize_rich_text(source): # Convert raw pseudo-HTML RichText source to a soup object # so it can be manipulated. soup = BeautifulSoup(source, 'html5lib') # Add data required to generate page links in Gatsby. for anchor in soup.find_all('a'): if anchor.attrs.get('linktype', '') == 'page': try: pages = Page.objects.live().public() page = pages.get(pk=anchor.attrs['id']).specific page_type = page.__class__.__name__ new_tag = soup.new_tag( 'a', href=page.get_url(), # Add dataset arguments to allow processing links on # the front-end. **{ 'data-page-type': page_type, 'data-page-slug': page.slug, 'data-page-service-slug': getattr( getattr(page, 'service', None), 'slug', None ) } ) new_tag.append(*anchor.contents) anchor.replace_with(new_tag) except Page.DoesNotExist: # If page does not exist, add empty anchor tag with text. new_tag = soup.new_tag('a') new_tag.append(*anchor.contents) anchor.replace_with(new_tag) # Convert raw pseudo-HTML RichText into a front-end RichText return str(RichText(str(soup)))
Example #9
Source File: opportunity.py From foundation.mozilla.org with Mozilla Public License 2.0 | 5 votes |
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)]
Example #10
Source File: styleguide.py From foundation.mozilla.org with Mozilla Public License 2.0 | 5 votes |
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)
Example #11
Source File: blog.py From foundation.mozilla.org with Mozilla Public License 2.0 | 5 votes |
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)
Example #12
Source File: edit_handlers.py From django-oscar-wagtail with MIT License | 5 votes |
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>"
Example #13
Source File: youtube_regrets_page.py From foundation.mozilla.org with Mozilla Public License 2.0 | 5 votes |
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)
Example #14
Source File: initiatives_page.py From foundation.mozilla.org with Mozilla Public License 2.0 | 5 votes |
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)
Example #15
Source File: bannered_campaign_page.py From foundation.mozilla.org with Mozilla Public License 2.0 | 5 votes |
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)
Example #16
Source File: test_page_queryset.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_empty_queryset_strict(self): with self.assertRaises(Page.DoesNotExist): Page.objects.none().first_common_ancestor(strict=True)
Example #17
Source File: test_page_queryset.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_all_pages_strict(self): with self.assertRaises(Page.DoesNotExist): Page.objects.first_common_ancestor(strict=True)
Example #18
Source File: navigation.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #19
Source File: editor_html.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
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>"
Example #20
Source File: campaign_page.py From foundation.mozilla.org with Mozilla Public License 2.0 | 4 votes |
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 Campaign Pages under namespace') campaigns = [CampaignPageFactory.create(parent=campaign_index_page) for i in range(5)] reseed(seed) print('Generating Donation Modals for Campaign Pages') [DonationModalsFactory.create(page=campaign) for campaign in campaigns] reseed(seed) try: CampaignPage.objects.get(title='single-page') print('single-page CampaignPage already exists') except CampaignPage.DoesNotExist: print('Generating single-page CampaignPage') CampaignPageFactory.create(parent=campaign_index_page, title='single-page') reseed(seed) try: CampaignPage.objects.get(title='multi-page') print('multi-page CampaignPage already exists.') except CampaignPage.DoesNotExist: print('Generating multi-page CampaignPage') multi_page_campaign = CampaignPageFactory(parent=campaign_index_page, title='multi-page') [CampaignPageFactory(parent=multi_page_campaign) for k in range(3)] reseed(seed)
Example #21
Source File: views.py From openstax-cms with GNU Affero General Public License v3.0 | 4 votes |
def duplicate(request, page): if request.method == 'POST': form = DuplicateForm(request.POST or None, user=request.user, page=page) if form.is_valid(): try: export_settings = {'root_page': Page.objects.get(pk=page), 'export_unpublished': False, 'export_documents': False, 'export_images': False, 'null_pk': True, 'null_fk': False, 'null_users': False} export_file = exporting.export_page(settings=export_settings) overwrite = { 'title': form.cleaned_data['new_title'], 'draft_title': form.cleaned_data['new_title'], 'slug': form.cleaned_data['new_slug'] } num_uploaded, num_failed, response = importing.import_page(export_file, form.cleaned_data['new_parent_page'], overwrites = overwrite) if not num_failed: messages.success( request, ungettext("%(count)s book duplicated.", "%(count)s books duplicated.", num_uploaded) % {'count': num_uploaded}) else: messages.success(request, _("%(uploaded)s book(s) were duplicated while %(skipped)s page(s) were skipped because they were already in the environment. %(error)s") % {'uploaded': num_uploaded, 'skipped': num_failed, 'error': response}) return redirect('wagtailadmin_explore', form.cleaned_data['new_parent_page'].pk) except Page.DoesNotExist: messages.error(request, _("Duplicate failed because the root book was not found.")) return redirect('wagtailadmin_explore', page.pk) else: form = DuplicateForm(request.POST or None, user=request.user, page=page) return render(request, 'duplicatebooks/duplicate.html', { 'form': form, 'pageid': page })
Example #22
Source File: forms.py From openstax-cms with GNU Affero General Public License v3.0 | 4 votes |
def __init__(self, *args, **kwargs): # DuplicatePage must be passed a 'page' kwarg indicating the page to be copied try: self.page = Page.objects.get(pk=kwargs.pop('page')) except Page.DoesNotExist: raise Http404("No MyModel matches the given query.") self.user = kwargs.pop('user', None) super().__init__(*args, **kwargs) self.fields['new_title'] = forms.CharField(initial=self.page.title, label=_("New title")) self.fields['new_slug'] = forms.SlugField(initial=self.page.slug, label=_("New slug")) self.fields['new_parent_page'] = forms.ModelChoiceField( initial=self.page.get_parent(), queryset=Page.objects.all(), widget=wagtailadmin_widgets.AdminPageChooser(can_choose_root=True, user_perms='copy_to'), label=_("New parent page"), help_text=_("This copy will be a child of this given parent page.") ) pages_to_copy = self.page.get_descendants(inclusive=True) subpage_count = pages_to_copy.count() - 1 if subpage_count > 0: self.fields['copy_subpages'] = forms.BooleanField( required=False, initial=True, label=_("Copy subpages"), help_text=ungettext( "This will copy %(count)s subpage.", "This will copy %(count)s subpages.", subpage_count) % {'count': subpage_count}) can_publish = self.page.permissions_for_user(self.user).can_publish_subpage() if can_publish: pages_to_publish_count = pages_to_copy.live().count() if pages_to_publish_count > 0: # In the specific case that there are no subpages, customise the field label and help text if subpage_count == 0: label = _("Publish copied page") help_text = _("This page is live. Would you like to publish its copy as well?") else: label = _("Publish copies") help_text = ungettext( "%(count)s of the pages being copied is live. Would you like to publish its copy?", "%(count)s of the pages being copied are live. Would you like to publish their copies?", pages_to_publish_count) % {'count': pages_to_publish_count} self.fields['publish_copies'] = forms.BooleanField( required=False, initial=True, label=label, help_text=help_text )