Home page can now host richt content

This commit is contained in:
Konstantin 2024-04-05 19:03:18 +02:00
parent 9b4bb6c9f1
commit 38733808ed
7 changed files with 191 additions and 5 deletions

View file

@ -1,4 +1,4 @@
from wagtail.blocks import RichTextBlock
from wagtail.blocks import RichTextBlock, BlockQuoteBlock
from wagtail.embeds.blocks import EmbedBlock
from base.blocks import StreamBlock, HeadingBlock, ImageBlock
@ -6,6 +6,7 @@ from wagtailcodeblock.blocks import CodeBlock
class BlogPostBlock(StreamBlock):
heading_block = HeadingBlock()
blockquote = BlockQuoteBlock()
paragraph = RichTextBlock(blank=True)
code = CodeBlock(label='Code snippet')
image_block = ImageBlock()

View file

@ -0,0 +1,22 @@
# Generated by Django 5.0.2 on 2024-04-05 16:56
import wagtail.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('blog', '0013_alter_blogpage_body'),
]
operations = [
migrations.AlterField(
model_name='blogpage',
name='body',
field=wagtail.fields.StreamField([('heading_block', wagtail.blocks.StructBlock([('heading_text', wagtail.blocks.CharBlock(form_classname='title', required=True)), ('size', wagtail.blocks.ChoiceBlock(blank=True, choices=[('', 'Select a heading size'), ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4')], required=False))])), ('blockquote', wagtail.blocks.BlockQuoteBlock()), ('paragraph', wagtail.blocks.RichTextBlock(blank=True)), ('code', wagtail.blocks.StructBlock([('language', wagtail.blocks.ChoiceBlock(choices=[('bash', 'Bash/Shell'), ('css', 'CSS'), ('dart', 'Dart'), ('docker', 'Docker'), ('elixir', 'Elixir'), ('go', 'Go'), ('html', 'HTML'), ('javascript', 'Javascript'), ('json', 'JSON'), ('kotlin', 'Kotlin'), ('python', 'Python'), ('rust', 'Rust'), ('swift', 'Swift'), ('toml', 'TOML'), ('yaml', 'YAML')], help_text='Coding language', identifier='language', label='Language')), ('code', wagtail.blocks.TextBlock(identifier='code', label='Code'))], label='Code snippet')), ('image_block', wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=True)), ('caption', wagtail.blocks.CharBlock(required=False)), ('attribution', wagtail.blocks.CharBlock(required=False))])), ('embed_block', wagtail.embeds.blocks.EmbedBlock(help_text='Insert a URL to embed. For example, https://www.youtube.com/watch?v=SGJFWirQ3ks', icon='media'))], blank=True, help_text='Write anything'),
),
]

View file

@ -14,6 +14,7 @@ from wagtail.snippets.models import register_snippet
from blog.blocks import BlogPostBlock
from wagtailseo.models import SeoMixin, SeoType
class BlogIndexPage(SeoMixin, Page):
intro = RichTextField(blank=True)
@ -29,6 +30,7 @@ class BlogIndexPage(SeoMixin, Page):
]
promote_panels = SeoMixin.seo_panels
class BlogTagIndexPage(Page):
def get_context(self, request):
@ -40,6 +42,7 @@ class BlogTagIndexPage(Page):
context['blogpages'] = blogpages
return context
class BlogPageTag(TaggedItemBase):
content_object = ParentalKey(
'BlogPage',
@ -47,6 +50,7 @@ class BlogPageTag(TaggedItemBase):
on_delete=models.CASCADE
)
class BlogPage(SeoMixin, Page):
date = models.DateField("Post date")
intro = models.TextField()
@ -104,6 +108,7 @@ class BlogPageGalleryImage(Orderable):
FieldPanel('caption'),
]
@register_snippet
class Author(models.Model):
name = models.CharField(max_length=255)
@ -121,4 +126,4 @@ class Author(models.Model):
return self.name
class Meta:
verbose_name_plural = 'Authors'
verbose_name_plural = 'Authors'