Skip to content
Permalink
Browse files

CTA Streamfield on 2 Page Types

  • Loading branch information
KalobTaulien committed Feb 4, 2019
1 parent 141ba93 commit 1f1c3fc2d9f62ccddb651d1081d21df69ff638e6
@@ -0,0 +1,22 @@
# Generated by Django 2.1.5 on 2019-02-04 16:13

from django.db import migrations
import streams.blocks
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks


class Migration(migrations.Migration):

dependencies = [
('flex', '0003_auto_20190201_1734'),
]

operations = [
migrations.AlterField(
model_name='flexpage',
name='content',
field=wagtail.core.fields.StreamField([('title_and_text', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(help_text='Add your title', required=True)), ('text', wagtail.core.blocks.TextBlock(help_text='Add additional text', required=True))])), ('full_richtext', streams.blocks.RichtextBlock()), ('simple_richtext', streams.blocks.SimpleRichtextBlock()), ('cards', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(help_text='Add your title', required=True)), ('cards', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=True)), ('title', wagtail.core.blocks.CharBlock(max_length=40, required=True)), ('text', wagtail.core.blocks.TextBlock(max_length=200, required=True)), ('button_page', wagtail.core.blocks.PageChooserBlock(required=False)), ('button_url', wagtail.core.blocks.URLBlock(help_text='If the button page above is selected, that will be used first.', required=False))])))])), ('cta', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(max_length=60, required=True)), ('text', wagtail.core.blocks.RichTextBlock(features=['bold', 'italic'], required=True)), ('button_page', wagtail.core.blocks.PageChooserBlock(required=False)), ('button_url', wagtail.core.blocks.URLBlock(required=False)), ('button_text', wagtail.core.blocks.CharBlock(default='Learn More', max_length=40, required=True))]))], blank=True, null=True),
),
]
@@ -19,6 +19,7 @@ class FlexPage(Page):
("full_richtext", blocks.RichtextBlock()),
("simple_richtext", blocks.SimpleRichtextBlock()),
("cards", blocks.CardBlock()),
("cta", blocks.CTABlock()),
],
null=True,
blank=True,
@@ -0,0 +1,20 @@
# Generated by Django 2.1.5 on 2019-02-04 16:13

from django.db import migrations
import wagtail.core.blocks
import wagtail.core.fields


class Migration(migrations.Migration):

dependencies = [
('home', '0004_auto_20190128_1547'),
]

operations = [
migrations.AddField(
model_name='homepage',
name='content',
field=wagtail.core.fields.StreamField([('cta', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.CharBlock(max_length=60, required=True)), ('text', wagtail.core.blocks.RichTextBlock(features=['bold', 'italic'], required=True)), ('button_page', wagtail.core.blocks.PageChooserBlock(required=False)), ('button_url', wagtail.core.blocks.URLBlock(required=False)), ('button_text', wagtail.core.blocks.CharBlock(default='Learn More', max_length=40, required=True))]))], blank=True, null=True),
),
]
@@ -1,10 +1,12 @@
from django.db import models

from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel, PageChooserPanel
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel, PageChooserPanel
from wagtail.core.fields import RichTextField, StreamField
from wagtail.images.edit_handlers import ImageChooserPanel

from streams import blocks


class HomePage(Page):
"""Home page model."""
@@ -27,16 +29,25 @@ class HomePage(Page):
blank=True,
on_delete=models.SET_NULL,
related_name="+"
)
)

content = StreamField(
[
("cta", blocks.CTABlock()),
],
null=True,
blank=True,
)

content_panels = Page.content_panels + [
FieldPanel("banner_title"),
FieldPanel("banner_subtitle"),
ImageChooserPanel("banner_image"),
PageChooserPanel("banner_cta")
PageChooserPanel("banner_cta"),
StreamFieldPanel("content"),
]

class Meta:

verbose_name = "Home Page"
verbose_name_plural = "Home Pages"
verbose_name_plural = "Home Pages"
@@ -12,5 +12,9 @@ <h1 class="display-4">{{ self.banner_title }}</h1>
{% if self.banner_cta %}
<a class="btn btn-primary btn-lg" href="#" role="button">@todo</a>
{% endif %}
</div>
</div>

{% for block in page.content %}
{% include_block block %}
{% endfor %}
{% endblock %}
@@ -0,0 +1,16 @@
{% load wagtailcore_tags %}

<div class="container mb-sm-5 mt-sm-5">
<div class="row">
<div class="col-md-5 offset-md-1 col-sm-12">
<h1>{{ self.title }}</h1>
{{ self.text|richtext }}

{% if self.button_page %}
<a href="{{ self.button_page.url }}">{{ self.button_text }}</a>
{% elif self.button_url %}
<a href="{{ self.button_url }}">{{ self.button_text }}</a>
{% endif %}
</div>
</div>
</div>
@@ -67,3 +67,18 @@ class Meta: # noqa
template = "streams/richtext_block.html"
icon = "edit"
label = "Simple RichText"


class CTABlock(blocks.StructBlock):
"""A simple call to action section."""

title = blocks.CharBlock(required=True, max_length=60)
text = blocks.RichTextBlock(required=True, features=["bold", "italic"])
button_page = blocks.PageChooserBlock(required=False)
button_url = blocks.URLBlock(required=False)
button_text = blocks.CharBlock(required=True, default='Learn More', max_length=40)

class Meta: # noqa
template = "streams/cta_block.html"
icon = "placeholder"
label = "Call to Action"

0 comments on commit 1f1c3fc

Please sign in to comment.
You can’t perform that action at this time.