diff --git a/bakerydemo/base/blocks.py b/bakerydemo/base/blocks.py index a2ea29646..7c7118d01 100644 --- a/bakerydemo/base/blocks.py +++ b/bakerydemo/base/blocks.py @@ -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): + """ + Define the custom blocks that `StreamField` will utilize + """ + + details_block = DetailsBlock() diff --git a/bakerydemo/base/fixtures/bakerydemo.json b/bakerydemo/base/fixtures/bakerydemo.json index 0921eb5a2..2fa26419d 100644 --- a/bakerydemo/base/fixtures/bakerydemo.json +++ b/bakerydemo/base/fixtures/bakerydemo.json @@ -9992,6 +9992,55 @@ "approved_go_live_at": null } }, + { + "model": "wagtailcore.revision", + "pk": 112, + "fields": { + "content_type": ["base", "standardpage"], + "base_content_type": ["wagtailcore", "page"], + "object_id": "87", + "submitted_for_moderation": false, + "created_at": "2023-09-01T16:55:15.360Z", + "user": ["editor"], + "object_str": "FAQ", + "content": { + "pk": 87, + "path": "00010002000A", + "depth": 3, + "numchild": 0, + "translation_key": "b0899639-6d67-44a3-a260-ca20622c9f7a", + "locale": 1, + "latest_revision": 112, + "live": true, + "has_unpublished_changes": false, + "first_published_at": "2023-06-28T15:55:17.810Z", + "last_published_at": null, + "live_revision": null, + "go_live_at": null, + "expire_at": null, + "expired": false, + "locked": false, + "locked_at": null, + "locked_by": null, + "title": "FAQ", + "draft_title": "FAQ", + "slug": "FAQ", + "content_type": 33, + "url_path": "/home/FAQ/", + "owner": 3, + "seo_title": "", + "show_in_menus": true, + "search_description": "", + "latest_revision_created_at": "2023-09-01T16:55:15.322Z", + "alias_of": null, + "introduction": "Welcome to the FAQ page of BakeryDemo! Here you'll find answers to commonly asked questions about BakeryDemo, Wagtail CMS, and how to contribute. Browse the questions below to find the information you need. Click on a question to reveal the answer.\r\n\r\nIf you have any other questions or need further assistance, feel free to reach out to us. Enjoy your experience with BakeryDemo and Wagtail!", + "image": 41, + "body": "[{\"type\": \"paragraph_block\", \"value\": \"
If you've gotten this far, congratulations - you're running an instance of a killer content management system written for and on top of Django, the framework for perfectionists with deadlines.
What does Wagtail get you that Django alone does not?\\u00a0
If you're new to Wagtail, there are two primary paths to learning:
One day when he came in from fishing, he found the same corn meal mush and molasses for dinner and being very tired of it, he decided to mix it with bread flour and yeast and baked it saying, "Anna Damn Her." The bread was so delicious that his neighbors baked it calling it Anadama Bread.
\", \"open\": true}, \"id\": \"ac1ceb7f-62c4-46a2-9183-399d0d0dcee8\"}, {\"type\": \"details_block\", \"value\": {\"summary\": \"What is the origin of Anadama bread?\", \"content\": \"Anadama bread is believed to have originated in New England, particularly in Massachusetts, USA. It is named after a local fisherman's wife, Anna, who is said to have created the recipe. Anadama bread has a rich history and has become a beloved traditional bread in the region, known for its unique flavor and texture.
\", \"open\": true}, \"id\": \"8ad8eeb2-1862-4da0-b29a-b26084bcadae\"}]", "origin": 3, "bread_type": 4, "ingredients": [] @@ -13142,6 +13226,7 @@ "introduction": "Anpan was first made in 1875, during the Meiji period, by a man called Yasubei Kimura, a samurai who lost his job with the rise of the conscript Imperial Army and the dissolution of the samurai as a social class.", "image": 34, "body": "[]", + "questions": "[]", "origin": 4, "bread_type": 5, "ingredients": [] @@ -13154,6 +13239,7 @@ "introduction": "Appam is a type of pancake made with fermented rice batter and coconut milk. It is a common food in Kerala, Tamil Nadu and Sri Lanka. It is eaten most frequently for breakfast or dinner.", "image": 28, "body": "[]", + "questions": "[]", "origin": 5, "bread_type": 6, "ingredients": [] @@ -13166,6 +13252,7 @@ "introduction": "Arepa is a type of food made of ground maize dough or cooked flour prominent in the cuisine of Colombia and Venezuela.", "image": 29, "body": "[]", + "questions": "[]", "origin": 6, "bread_type": 7, "ingredients": [] @@ -13178,6 +13265,7 @@ "introduction": "Though the origins of bagels are somewhat obscure, it is known that they were widely consumed in eastern European Jewish communities from the 17th century.", "image": 30, "body": "[]", + "questions": "[]", "origin": 8, "bread_type": 4, "ingredients": [] @@ -13190,6 +13278,7 @@ "introduction": "A baguette has a diameter of about 5 or 6 centimetres and a usual length of about 65 centimetres (26 in), although a baguette can be up to a metre (39 in) long.", "image": 31, "body": "[]", + "questions": "[]", "origin": 9, "bread_type": 4, "ingredients": [] @@ -13202,6 +13291,7 @@ "introduction": "Bammies, like wheat bread and tortillas, are served at any meal or consumed as a snack.", "image": 32, "body": "[]", + "questions": "[]", "origin": 11, "bread_type": 2, "ingredients": [] @@ -13214,6 +13304,7 @@ "introduction": "When consumed, bazin may be \"crumpled and eaten with the fingers.\"", "image": 33, "body": "[]", + "questions": "[]", "origin": 18, "bread_type": 11, "ingredients": [] @@ -13226,6 +13317,7 @@ "introduction": "Bhakri is a round flat unleavened bread often used in the cuisine of the state of mainly Maharashtra, but also in Gujarat.", "image": 40, "body": "[]", + "questions": "[]", "origin": 21, "bread_type": 14, "ingredients": [] @@ -13238,6 +13330,7 @@ "introduction": "Rye bread is a type of bread made with various proportions of flour from rye grain", "image": 39, "body": "[]", + "questions": "[]", "origin": 12, "bread_type": 16, "ingredients": [] @@ -13250,6 +13343,7 @@ "introduction": "Perakai is made for special occasions like birthday parties, engagement parties or holidays.", "image": 36, "body": "[{\"type\": \"embed_block\", \"value\": \"https://www.youtube.com/watch?v=mwrGSfiB1Mg\", \"id\": \"90411c51-e84c-421e-aae0-d190e8430281\"}]", + "questions": "[]", "origin": 24, "bread_type": 2, "ingredients": [] @@ -13385,7 +13479,18 @@ "fields": { "introduction": "Things to know about this demo site", "image": 41, - "body": "[{\"type\": \"paragraph_block\", \"value\": \"If you've gotten this far, congratulations - you're running an instance of a killer content management system written for and on top of Django, the framework for perfectionists with deadlines.
What does Wagtail get you that Django alone does not?\\u00a0
If you're new to Wagtail, there are two primary paths to learning:
If you've gotten this far, congratulations - you're running an instance of a killer content management system written for and on top of Django, the framework for perfectionists with deadlines.
What does Wagtail get you that Django alone does not?\\u00a0
If you're new to Wagtail, there are two primary paths to learning:
BakeryDemo is a sample website designed to showcase the capabilities of the Wagtail Content Management System.
\", \"open\": true}, \"id\": \"081a0c00-999e-4106-a954-11f2c3f54a40\"}, {\"type\": \"details_block\", \"value\": {\"summary\": \"What is Wagtail?\", \"content\": \"Wagtail is a flexible and user-friendly open-source CMS built on the Python web framework Django. It allows you to create and manage websites with ease.
\", \"open\": true}, \"id\": \"4bdb463a-b6c7-4873-957a-6ed4f797ea3a\"}, {\"type\": \"details_block\", \"value\": {\"summary\": \"Where can I find the Wagtail documentation?\", \"content\": \"You can find the official Wagtail documentation at the following link: Wagtail Documentation
\", \"open\": true}, \"id\": \"d8697c33-1649-4650-b731-7b25e38dd6b3\"}, {\"type\": \"details_block\", \"value\": {\"summary\": \"How can I contribute to BakeryDemo?\", \"content\": \"We welcome contributions to BakeryDemo! You can find detailed guidelines and instructions on how to contribute in our BakeryDemo Contribution Guide.
\", \"open\": true}, \"id\": \"c3524098-d468-46b5-a225-db92e7e6b742\"}, {\"type\": \"details_block\", \"value\": {\"summary\": \"How can I contribute to the Wagtail project?\", \"content\": \"If you are interested in contributing to the Wagtail project itself, you can find information on how to get involved and contribute in the official Wagtail Contribution Guide.
\", \"open\": true}, \"id\": \"54152127-065d-40e9-94ec-5506ce500675\"}]" } }, { diff --git a/bakerydemo/base/migrations/0019_standardpage_questions.py b/bakerydemo/base/migrations/0019_standardpage_questions.py new file mode 100644 index 000000000..920b06ccd --- /dev/null +++ b/bakerydemo/base/migrations/0019_standardpage_questions.py @@ -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", + ), + ), + ] diff --git a/bakerydemo/base/models.py b/bakerydemo/base/models.py index 3ae5335f2..cd7322319 100644 --- a/bakerydemo/base/models.py +++ b/bakerydemo/base/models.py @@ -30,7 +30,7 @@ ) from wagtail.search import index -from .blocks import BaseStreamBlock +from .blocks import BaseStreamBlock, DetailsStreamBlock class Person( @@ -200,10 +200,14 @@ class StandardPage(Page): body = StreamField( BaseStreamBlock(), verbose_name="Page body", blank=True, use_json_field=True ) + questions = StreamField( + DetailsStreamBlock(), verbose_name="Questions", blank=True, use_json_field=True + ) content_panels = Page.content_panels + [ FieldPanel("introduction"), FieldPanel("body"), FieldPanel("image"), + FieldPanel("questions"), ] diff --git a/bakerydemo/breads/migrations/0007_breadpage_questions.py b/bakerydemo/breads/migrations/0007_breadpage_questions.py new file mode 100644 index 000000000..99d19df91 --- /dev/null +++ b/bakerydemo/breads/migrations/0007_breadpage_questions.py @@ -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 = [ + ("breads", "0006_breadingredient_expire_at_breadingredient_expired_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="breadpage", + 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", + ), + ), + ] diff --git a/bakerydemo/breads/models.py b/bakerydemo/breads/models.py index a2be7e9b9..9983a462e 100644 --- a/bakerydemo/breads/models.py +++ b/bakerydemo/breads/models.py @@ -7,7 +7,7 @@ from wagtail.models import DraftStateMixin, Page, RevisionMixin from wagtail.search import index -from bakerydemo.base.blocks import BaseStreamBlock +from bakerydemo.base.blocks import BaseStreamBlock, DetailsStreamBlock class Country(models.Model): @@ -94,6 +94,9 @@ class BreadPage(Page): body = StreamField( BaseStreamBlock(), verbose_name="Page body", blank=True, use_json_field=True ) + questions = StreamField( + DetailsStreamBlock(), verbose_name="Questions", blank=True, use_json_field=True + ) origin = models.ForeignKey( Country, on_delete=models.SET_NULL, @@ -119,6 +122,7 @@ class BreadPage(Page): FieldPanel("introduction"), FieldPanel("image"), FieldPanel("body"), + FieldPanel("questions"), FieldPanel("origin"), FieldPanel("bread_type"), MultiFieldPanel( diff --git a/bakerydemo/static/css/main.css b/bakerydemo/static/css/main.css index 129d78c68..0f1c3c893 100644 --- a/bakerydemo/static/css/main.css +++ b/bakerydemo/static/css/main.css @@ -1261,6 +1261,32 @@ footer { text-shadow: 0 0 7px rgb(0 0 0 / 50%); } +.details-block { + margin-bottom: 0; + background-color: var(--cream); + padding: 20px; + border: 1px solid var(--border-grey); +} + +.details-block summary { + font-family: var(--font--secondary); + font-weight: 700; + font-size: var(--font-md); + line-height: 1.55; + cursor: pointer; +} + +.details-block .details-content { + font-family: var(--font--secondary); + font-size: var(--font-md); + line-height: 1.55; + padding-top: 10px; +} + +.details-block .details-content p { + margin-bottom: 0; +} + @media (min-width: 992px) { .bread-detail__meta { background-color: var(--cream); diff --git a/bakerydemo/templates/base/standard_page.html b/bakerydemo/templates/base/standard_page.html index bd8f0b3a5..d4e0b6639 100644 --- a/bakerydemo/templates/base/standard_page.html +++ b/bakerydemo/templates/base/standard_page.html @@ -15,6 +15,9 @@ {% endif %} {{ page.body }} + {% if page.questions %} + {{page.questions}} + {% endif %} diff --git a/bakerydemo/templates/blocks/details_block.html b/bakerydemo/templates/blocks/details_block.html new file mode 100644 index 000000000..fa656173a --- /dev/null +++ b/bakerydemo/templates/blocks/details_block.html @@ -0,0 +1,6 @@ +