How to use wagtail - 10 common examples

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 torchbox / wagtailapi / tests / models.py View on Github external
'related_links',
    ) + ContactFieldsMixin.api_fields

    search_fields = Page.search_fields + (
        index.SearchField('first_name'),
        index.SearchField('last_name'),
        index.SearchField('intro'),
        index.SearchField('biography'),
    )

class PersonPageRelatedLink(Orderable, AbstractRelatedLink):
    page = ParentalKey('PersonPage', related_name='related_links')

PersonPage.content_panels = Page.content_panels + [
    FieldPanel('first_name'),
    FieldPanel('last_name'),
    FieldPanel('intro', classname="full"),
    FieldPanel('biography', classname="full"),
    ImageChooserPanel('image'),
    MultiFieldPanel(ContactFieldsMixin.panels, "Contact"),
    InlinePanel(PersonPage, 'related_links', label="Related links"),
]

PersonPage.promote_panels = [
    MultiFieldPanel(Page.promote_panels, "Common page configuration"),
    ImageChooserPanel('feed_image'),
]


# Contact page

class ContactPage(Page, ContactFieldsMixin):
github wagtail / wagtail / wagtail / contrib / routable_page / tests.py View on Github external
def setUp(self):
        self.home_page = Page.objects.get(id=2)

        events_page = self.home_page.add_child(instance=Page(title='Events', live=True))

        second_site = Site.objects.create(
            hostname='events.local',
            port=80,
            root_page=events_page,
        )

        self.routable_page = self.home_page.add_child(instance=RoutablePageTest(
            title="Routable Page",
            live=True,
        ))

        self.rf = RequestFactory()
        self.request = self.rf.get(self.routable_page.url)
        self.request.site = Site.find_for_request(self.request)
        self.context = {'request': self.request}
github mozilla / foundation.mozilla.org / network-api / networkapi / wagtailpages / pagemodels / customblocks / latest_profile_list.py View on Github external
required=True,
        help_text='Pick up to 48 profiles.',
    )

    advanced_filter_header = blocks.StaticBlock(
        label=' ',
        admin_text='-------- ADVANCED FILTERS: OPTIONS TO DISPLAY FEWER, MORE TARGETED RESULTS. --------',
    )

    profile_type = blocks.CharBlock(
        required=False,
        default='',
        help_text='Example: Fellow.'
    )

    program_type = blocks.CharBlock(
        required=False,
        default='',
        help_text='Example: Tech Policy.'
    )

    year = blocks.CharBlock(
        required=False,
        default=''
    )

    def get_context(self, value, parent_context=None, no_limit=False, initial_year=False, ordering=False):
        context = super().get_context(value, parent_context=parent_context)

        query_args = {
            'limit': value['max_number_of_results'],
            'profile_type': value['profile_type'],
github torchbox / wagtailapi / tests / models.py View on Github external
# PAGE MODELS
# =============================

# Home page

class HomePage(Page):
    body = RichTextField(blank=True)

    api_fields = (
        'body',
        'carousel_items',
        'related_links',
    )

    search_fields = Page.search_fields + (
        index.SearchField('body'),
    )

    class Meta:
        verbose_name = "Homepage"


class HomePageCarouselItem(Orderable, AbstractCarouselItem):
    page = ParentalKey('HomePage', related_name='carousel_items')

class HomePageRelatedLink(Orderable, AbstractRelatedLink):
    page = ParentalKey('HomePage', related_name='related_links')

HomePage.content_panels = Page.content_panels + [
    FieldPanel('body', classname="full"),
github springload / wagtailmodelchoosers / tests / testapp / core / migrations / 0001_initial.py View on Github external
('wagtailcore', '0040_page_draft_title'),
    ]

    operations = [
        migrations.CreateModel(
            name='SimpleModel',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=70)),
            ],
        ),
        migrations.CreateModel(
            name='SimplePage',
            fields=[
                ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
                ('rich_text', wagtail.core.fields.RichTextField(blank=True)),
                ('optional_simple_model', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='core.SimpleModel')),
                ('required_simple_model', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.SimpleModel')),
            ],
            options={
                'abstract': False,
            },
            bases=('wagtailcore.page',),
        ),
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