-
Notifications
You must be signed in to change notification settings - Fork 544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved: Add new custom block "DetailsBlock" with expanding answers and demonstrate it in a BreadPage and in a new FAQ page #425
Open
gzark1
wants to merge
8
commits into
wagtail:main
Choose a base branch
from
gzark1:feature/details-block-implementation2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e1c957e
Create DetailsBlock and DetailsStreamBlock
gzark1 e660448
Add details_block.html template
gzark1 842992a
Update main.css
gzark1 586f470
Add import in blocks.py
gzark1 9ff43f1
Add DetailsStreamBlock in bread page and standard page, update their …
gzark1 717f8bf
Make migrations, create data for the new feature and store in bakeryd…
gzark1 7753388
reformat
gzark1 2eb2cc5
Merge branch 'main' into feature/details-block-implementation2
cnk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
StructBlock, | ||
TextBlock, | ||
) | ||
from wagtail.blocks.field_block import BooleanBlock | ||
from wagtail.embeds.blocks import EmbedBlock | ||
from wagtail.images.blocks import ImageChooserBlock | ||
|
||
|
@@ -60,6 +61,22 @@ class Meta: | |
template = "blocks/blockquote.html" | ||
|
||
|
||
class DetailsBlock(StructBlock): | ||
""" | ||
Custom `StructBlock` for creating a details block with summary, content, and open fields. | ||
""" | ||
|
||
summary = CharBlock(required=True) | ||
content = RichTextBlock(required=True) | ||
open = BooleanBlock( | ||
required=False, default=True, label="Open", help_text="Open by default" | ||
) | ||
|
||
class Meta: | ||
icon = "collapse-down" | ||
template = "blocks/details_block.html" | ||
|
||
|
||
# StreamBlocks | ||
class BaseStreamBlock(StreamBlock): | ||
""" | ||
|
@@ -77,3 +94,12 @@ class BaseStreamBlock(StreamBlock): | |
icon="media", | ||
template="blocks/embed_block.html", | ||
) | ||
|
||
|
||
# StreamBlocks for Details | ||
class DetailsStreamBlock(StreamBlock): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m really surprised we’re not adding this to |
||
""" | ||
Define the custom blocks that `StreamField` will utilize | ||
""" | ||
|
||
details_block = DetailsBlock() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Generated by Django 4.2.2 on 2023-06-28 15:39 | ||
|
||
from django.db import migrations | ||
import wagtail.blocks | ||
import wagtail.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("base", "0018_add_genericsettings_and_sitesettings"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="standardpage", | ||
name="questions", | ||
field=wagtail.fields.StreamField( | ||
[ | ||
( | ||
"details_block", | ||
wagtail.blocks.StructBlock( | ||
[ | ||
("summary", wagtail.blocks.CharBlock(required=True)), | ||
( | ||
"content", | ||
wagtail.blocks.RichTextBlock(required=True), | ||
), | ||
( | ||
"open", | ||
wagtail.blocks.BooleanBlock( | ||
default=True, | ||
help_text="Open by default", | ||
label="Open", | ||
required=False, | ||
), | ||
), | ||
] | ||
), | ||
) | ||
], | ||
blank=True, | ||
use_json_field=True, | ||
verbose_name="Questions", | ||
), | ||
), | ||
] |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not too clear why we are using a
<details>
element in HTML if it’s to have those blocks opened by default. Could we default to "False" instead?I’d also suggest removing the label if it just repeats the field identifier, and writing a more descriptive help text or removing it (stating the default value isn’t too helpful).