Home page can now host richt content
This commit is contained in:
parent
9b4bb6c9f1
commit
38733808ed
7 changed files with 191 additions and 5 deletions
136
home/migrations/0006_alter_homepage_body.py
Normal file
136
home/migrations/0006_alter_homepage_body.py
Normal file
|
@ -0,0 +1,136 @@
|
|||
# Generated by Django 5.0.2 on 2024-04-05 16:56
|
||||
|
||||
import json
|
||||
import wagtail.blocks
|
||||
import wagtail.embeds.blocks
|
||||
import wagtail.fields
|
||||
import wagtail.images.blocks
|
||||
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def convert_to_streamfield(apps, schema_editor):
|
||||
HomePage = apps.get_model("home", "HomePage")
|
||||
for page in HomePage.objects.all():
|
||||
page.body = json.dumps(
|
||||
[{"type": "paragraph", "value": page.body}],
|
||||
cls=DjangoJSONEncoder
|
||||
)
|
||||
page.save()
|
||||
|
||||
|
||||
def convert_to_richtext(apps, schema_editor):
|
||||
HomePage = apps.get_model("home", "HomePage")
|
||||
for page in HomePage.objects.all():
|
||||
if page.body:
|
||||
stream = json.loads(page.body)
|
||||
page.body = "".join([
|
||||
child["value"] for child in stream
|
||||
if child["type"] == "paragraph"
|
||||
])
|
||||
page.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('home', '0005_homepage_canonical_url_homepage_og_image_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
convert_to_streamfield,
|
||||
convert_to_richtext,
|
||||
),
|
||||
|
||||
migrations.AlterField(
|
||||
model_name='homepage',
|
||||
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))])),
|
||||
('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')),
|
||||
('blockquote', wagtail.blocks.BlockQuoteBlock()), ('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'),
|
||||
),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue