How to use the wagtail.core.models.Page.objects.get function in wagtail

To help you get started, we’ve selected a few wagtail examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wagtail / wagtail-generic-chooser / tests / tests.py View on Github external
def test_pagination(self):
        homepage = Page.objects.get(depth=2)
        for i in range(0, 25):
            homepage.add_child(title='Page %d' % i)

        # fetch page 1
        response = self.client.get('/admin/api-page-chooser/')
        self.assertEqual(response.status_code, 200)

        response_json = json.loads(response.content)
        self.assertEqual(response_json['step'], 'choose')
        self.assertInHTML(
            '<p>Page 1 of 3.</p>',
            response_json['html']
        )
        self.assertInHTML(
            '<a class="icon icon-arrow-right-after" data-page="2" href="#">Next</a>',
            response_json['html']
github thelabnyc / wagtail_blog / blog / tests.py View on Github external
def setUp(self):
        home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('test', 'test@test.test', 'pass')
        self.xml_path = "example_export.xml"
        self.blog_index = home.add_child(instance=BlogIndexPage(
            title='Blog Index', slug='blog', search_description="x",
            owner=self.user))
github neon-jungle / wagtailmodelchooser / tests / test_admin_form.py View on Github external
def setUp(self):
        super(TestAdminForm, self).setUp()

        self.login()
        self.home_page = Page.objects.get(pk=2)

        Author.objects.bulk_create([
            Author(name='Ann Leckie'),
            Author(name='Iain M. Banks'),
            Author(name='Ursula K. Le Guin'),
            Author(name='Terry Pratchett'),
        ])
github wagtail / wagtail-generic-chooser / tests / tests.py View on Github external
def test_search(self):
        homepage = Page.objects.get(depth=2)
        red_page = homepage.add_child(title='A red page')
        another_red_page = homepage.add_child(title='Another red page')
        green_page = homepage.add_child(title='A green page')

        response = self.client.get('/admin/api-page-chooser/')
        self.assertEqual(response.status_code, 200)
        response_json = json.loads(response.content)
        self.assertEqual(response_json['step'], 'choose')

        # response should include a search box
        self.assertInHTML(
            '<input id="id_q" required="" placeholder="Search" name="q" type="text">',
            response_json['html']
        )
        self.assertInHTML(
            '<a href="/admin/api-page-chooser/%d/" class="item-choice">A red page</a>' % red_page.id,
github wagtail / wagtail-localize / wagtail_localize / translation / engines / pofile / tests.py View on Github external
def create_test_page(**kwargs):
    parent = kwargs.pop("parent", None) or Page.objects.get(id=1)
    page = parent.add_child(instance=TestPage(**kwargs))
    revision = page.save_revision()
    revision.publish()
    return page
github wagtail / wagtail-localize / wagtail_localize / translation / engines / google_translate / tests.py View on Github external
def create_test_page(**kwargs):
    parent = kwargs.pop("parent", None) or Page.objects.get(id=1)
    page = parent.add_child(instance=TestPage(**kwargs))
    revision = page.save_revision()
    revision.publish()
    return page
github wagtail / wagtail / wagtail / wagtailadmin / views / userbar.py View on Github external
def for_frontend(request, page_id):
    items = [
        EditPageItem(Page.objects.get(id=page_id)),
        AddPageItem(Page.objects.get(id=page_id)),
    ]

    for fn in hooks.get_hooks('construct_wagtail_userbar'):
        fn(request, items)

    # Render the items
    rendered_items = [item.render(request) for item in items]

    # Remove any unrendered items
    rendered_items = [item for item in rendered_items if item]

    # Render the edit bird
    return render(request, 'wagtailadmin/userbar/base.html', {
        'items': rendered_items,
    })
github wagtail / wagtail / wagtail / wagtailadmin / templatetags / wagtailuserbar.py View on Github external
return ''

    # Dont render anything if the page has not been saved - i.e. a preview
    if page.pk is None:
        return ''

    try:
        revision_id = request.revision_id
    except AttributeError:
        revision_id = None

    if revision_id is None:
        items = [
            AdminItem(),
            ExplorePageItem(Page.objects.get(id=page.id)),
            EditPageItem(Page.objects.get(id=page.id)),
            AddPageItem(Page.objects.get(id=page.id)),
        ]
    else:
        items = [
            AdminItem(),
            ExplorePageItem(PageRevision.objects.get(id=revision_id).page),
            EditPageItem(PageRevision.objects.get(id=revision_id).page),
            AddPageItem(PageRevision.objects.get(id=revision_id).page),
            ApproveModerationEditPageItem(PageRevision.objects.get(id=revision_id)),
            RejectModerationEditPageItem(PageRevision.objects.get(id=revision_id)),
        ]

    for fn in hooks.get_hooks('construct_wagtail_userbar'):
        fn(request, items)

    # Render the items
github mozilla / foundation.mozilla.org / network-api / networkapi / wagtailpages / factory / campaign_page.py View on Github external
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)
github praekeltfoundation / molo / molo / core / api / importers.py View on Github external
'''
        Recreates one-to-many relationship
        '''
        iterable = self.record_keeper.foreign_to_many_foreign_map[key]
        for foreign_page_id, foreign_page_id_list in iteritems(iterable):

            # Assumption: local page has been indexed and exists
            # TODO: handle case where it doesn't exist
            local_page_id = self.record_keeper.get_local_page(foreign_page_id)
            local_page = Page.objects.get(id=local_page_id).specific

            for _foreign_page_id in foreign_page_id_list:
                try:
                    local_version_page_id = (self.record_keeper
                                             .get_local_page(_foreign_page_id))
                    foreign_page = Page.objects.get(
                        id=local_version_page_id).specific
                    realtionship_object = class_(page=local_page)
                    setattr(realtionship_object, attribute_name, foreign_page)
                    realtionship_object.save()
                except Exception as e:
                    context = {
                        "exception": e,
                        "function_schema": ("recreate_relationships"
                                            "(class, attribute_name, key)"),
                        "attribute_name": str(attribute_name),
                        "key": str(key),
                        "class": str(class_),
                        "foreign_page_id": str(foreign_page_id),
                    }
                    self.log(ERROR, "recreating relationships",
                             context=context)