feat: home page with cta

This commit is contained in:
Konstantin 2024-02-29 21:44:43 +01:00
parent 75662f9d98
commit 72bf6bffb8
6 changed files with 87 additions and 14 deletions

View file

@ -0,0 +1,36 @@
# Generated by Django 5.0.2 on 2024-02-29 20:42
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0003_homepage_body'),
('wagtailcore', '0091_remove_revision_submitted_for_moderation'),
('wagtailimages', '0025_alter_image_file_alter_rendition_file'),
]
operations = [
migrations.AddField(
model_name='homepage',
name='hero_cta',
field=models.CharField(blank=True, help_text='Text to display on Call to Action', max_length=255, verbose_name='Hero CTA'),
),
migrations.AddField(
model_name='homepage',
name='hero_cta_link',
field=models.ForeignKey(blank=True, help_text='Choose a page to link to for the Call to Action', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailcore.page', verbose_name='Hero CTA link'),
),
migrations.AddField(
model_name='homepage',
name='hero_text',
field=models.CharField(blank=True, help_text='Write an introduction for the site', max_length=255),
),
migrations.AddField(
model_name='homepage',
name='image',
field=models.ForeignKey(blank=True, help_text='Homepage image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.image'),
),
]

View file

@ -2,11 +2,47 @@ from django.db import models
from wagtail.models import Page from wagtail.models import Page
from wagtail.fields import RichTextField from wagtail.fields import RichTextField
from wagtail.admin.panels import FieldPanel from wagtail.admin.panels import FieldPanel, MultiFieldPanel
class HomePage(Page): class HomePage(Page):
image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
help_text="Homepage image",
)
hero_text = models.CharField(
blank=True,
max_length=255, help_text="Write an introduction for the site"
)
hero_cta = models.CharField(
blank=True,
verbose_name="Hero CTA",
max_length=255,
help_text="Text to display on Call to Action",
)
hero_cta_link = models.ForeignKey(
"wagtailcore.Page",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
verbose_name="Hero CTA link",
help_text="Choose a page to link to for the Call to Action",
)
body = RichTextField(blank=True) body = RichTextField(blank=True)
content_panels = Page.content_panels + [ content_panels = Page.content_panels + [
MultiFieldPanel(
[
FieldPanel("image"),
FieldPanel("hero_text"),
FieldPanel("hero_cta"),
FieldPanel("hero_cta_link"),
],
heading="Hero section",
),
FieldPanel('body'), FieldPanel('body'),
] ]

View file

@ -1,18 +1,19 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load static %} {% load wagtailcore_tags wagtailimages_tags %}
{% load wagtailcore_tags %}
{% block body_class %}template-homepage{% endblock %} {% block body_class %}template-homepage{% endblock %}
{% block extra_css %}
{% comment %}
Delete the line below if you're just getting started and want to remove the welcome screen!
{% endcomment %}
<link rel="stylesheet" href="{% static 'css/welcome_page.css' %}">
{% endblock extra_css %}
<!-- replace everything below with: -->
{% block content %} {% block content %}
<div>
<h1>{{ page.title }}</h1>
{% image page.image fill-480x320 %}
<p>{{ page.hero_text }}</p>
{% if page.hero_cta_link %}
<a href="{% pageurl page.hero_cta_link %}">
{% firstof page.hero_cta page.hero_cta_link.title %}
</a>
{% endif %}
</div>
{{ page.body|richtext }} {{ page.body|richtext }}
{% endblock %} {% endblock content %}

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB