-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1067 from torchbox/feature/3217-further-info-bloc…
…ks-display #3217 - GUIDE PAGES | Enable multiple 'Further info' blocks display
- Loading branch information
Showing
5 changed files
with
198 additions
and
17 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
rca/guides/migrations/0030_guidepage_further_information_block.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Generated by Django 4.2.16 on 2025-01-13 14:55 | ||
|
||
from django.db import migrations | ||
import wagtail.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("guides", "0029_accordion_streamfield_block"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="guidepage", | ||
name="further_information_block", | ||
field=wagtail.fields.StreamField( | ||
[("accordion", 9)], | ||
blank=True, | ||
block_lookup={ | ||
0: ("wagtail.blocks.CharBlock", (), {}), | ||
1: ( | ||
"wagtail.blocks.CharBlock", | ||
(), | ||
{ | ||
"help_text": "A large heading diplayed next to the block", | ||
"required": False, | ||
}, | ||
), | ||
2: ( | ||
"wagtail.blocks.CharBlock", | ||
(), | ||
{ | ||
"help_text": "The text to display when the accordion is collapsed", | ||
"required": False, | ||
}, | ||
), | ||
3: ( | ||
"wagtail.blocks.RichTextBlock", | ||
(), | ||
{ | ||
"features": [ | ||
"h2", | ||
"h3", | ||
"bold", | ||
"italic", | ||
"image", | ||
"embed", | ||
"ul", | ||
"ol", | ||
"link", | ||
], | ||
"help_text": "The content shown when the accordion expanded", | ||
}, | ||
), | ||
4: ("wagtail.blocks.CharBlock", (), {"required": False}), | ||
5: ("wagtail.blocks.URLBlock", (), {"required": False}), | ||
6: ( | ||
"wagtail.blocks.StructBlock", | ||
[[("title", 4), ("url", 5)]], | ||
{ | ||
"help_text": "An optional link to display below the expanded content", | ||
"required": False, | ||
}, | ||
), | ||
7: ( | ||
"wagtail.blocks.StructBlock", | ||
[ | ||
[ | ||
("heading", 1), | ||
("preview_text", 2), | ||
("body", 3), | ||
("link", 6), | ||
] | ||
], | ||
{}, | ||
), | ||
8: ("wagtail.blocks.ListBlock", (7,), {}), | ||
9: ( | ||
"wagtail.blocks.StructBlock", | ||
[[("heading", 0), ("items", 8)]], | ||
{}, | ||
), | ||
}, | ||
), | ||
), | ||
] |
63 changes: 63 additions & 0 deletions
63
rca/guides/migrations/0031_migrate_further_information_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Generated by Django 4.2.16 on 2025-01-13 15:08 | ||
import json | ||
|
||
from django.db import migrations | ||
from wagtail.blocks import StreamValue | ||
from django.core.serializers.json import DjangoJSONEncoder | ||
|
||
|
||
def migrate_further_information_to_block(apps, schema_editor): | ||
# Get the model where the fields are defined | ||
GuidePage = apps.get_model('guides', 'GuidePage') | ||
|
||
for page in GuidePage.objects.all(): | ||
# Create an empty list to hold the StreamField data | ||
new_stream_data = [] | ||
|
||
# If there's a further_information_title and/or further_information, add them to the new block. | ||
if page.further_information_title or page.further_information: | ||
|
||
# Add accordion items from `further_information` StreamField | ||
accordion_data = [] | ||
for item in page.further_information: | ||
accordion_data.append({ | ||
'heading': item.value.get('heading', ''), | ||
'preview_text': item.value.get('preview_text', ''), | ||
'body': item.value.get('body').source if item.value.get('body') else '', | ||
'link': { | ||
'title': item.value.get('link').get('title', ''), | ||
'url': item.value.get('link').get('url', ''), | ||
}, | ||
}) | ||
|
||
# Add the heading and set the accordion items | ||
accordion_block = { | ||
'type': 'accordion', | ||
'value': { | ||
'heading': page.further_information_title, | ||
'items': accordion_data, | ||
}, | ||
} | ||
|
||
# Append the new block data to the StreamField | ||
new_stream_data.append(accordion_block) | ||
|
||
# Assign the new StreamField value to `further_information_block` | ||
page.further_information_block = StreamValue( | ||
page.further_information_block.stream_block, | ||
new_stream_data, | ||
is_lazy=True, | ||
) | ||
|
||
# Save the instance | ||
page.save() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("guides", "0030_guidepage_further_information_block"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(migrate_further_information_to_block, reverse_code=migrations.RunPython.noop), | ||
] |
21 changes: 21 additions & 0 deletions
21
rca/guides/migrations/0032_remove_old_further_information_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 4.2.16 on 2025-01-16 01:28 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("guides", "0031_migrate_further_information_data"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="guidepage", | ||
name="further_information", | ||
), | ||
migrations.RemoveField( | ||
model_name="guidepage", | ||
name="further_information_title", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters