Skip to content

Commit

Permalink
Wire up factory generation for the new block
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhowbrook committed Dec 11, 2023
1 parent 9d82c9b commit f58ce52
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
5 changes: 3 additions & 2 deletions network-api/networkapi/mozfest/customblocks/card_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from wagtail.images.blocks import ImageChooserBlock

"""
The following card and grid defunctions are specifically for Mozfest.
The following card and grid definitions are specifically for Mozfest.
They are based on wagtailpages.pagemodels.customblocks.card_grid.py
but have been modified to fit the Mozfest design.
"""
Expand All @@ -29,9 +29,10 @@ class MozfestCardGrid(blocks.StructBlock):


class MozfestCardGridBlock(blocks.StructBlock):
heading = blocks.CharBlock(help_text="Heading for the block.")
cards = blocks.ListBlock(MozfestCardGrid(), help_text="Please use a minimum of 2 cards.")

class Meta:
icon = "placeholder"
template = "fragments/blocks/mozfest_card_grid_block.html"
label = "Mozfest Card Grid Block"
label = "Mozfest Card Grid"
2 changes: 1 addition & 1 deletion network-api/networkapi/mozfest/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from networkapi.wagtailpages.factory.image_factory import ImageFactory
from networkapi.wagtailpages.factory.signup import SignupFactory

streamfield_fields = ["paragraph", "image", "spacer", "quote"]
streamfield_fields = ["paragraph", "image", "spacer", "quote", "mozfest_card_grid"]
Faker.add_provider(StreamfieldProvider)

is_review_app = False
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.23 on 2023-12-11 15:41
# Generated by Django 3.2.23 on 2023-12-11 16:31

import wagtail.blocks
import wagtail.blocks.static_block
Expand Down Expand Up @@ -62,12 +62,7 @@ class Migration(migrations.Migration):
),
),
("title", wagtail.blocks.CharBlock(help_text="Heading for the card.")),
(
"body",
wagtail.blocks.TextBlock(
help_text="Body text of the card.", required=False
),
),
("body", wagtail.blocks.TextBlock(help_text="Body text of the card.")),
(
"link_url",
wagtail.blocks.CharBlock(
Expand Down Expand Up @@ -1613,6 +1608,52 @@ class Migration(migrations.Migration):
[("signup", wagtail.snippets.blocks.SnippetChooserBlock("wagtailpages.Signup"))]
),
),
(
"mozfest_card_grid",
wagtail.blocks.StructBlock(
[
("heading", wagtail.blocks.CharBlock(help_text="Heading for the block.")),
(
"cards",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"alt_text",
wagtail.blocks.CharBlock(
help_text="Alt text for card's image.", required=False
),
),
("title", wagtail.blocks.CharBlock(help_text="Heading for the card.")),
(
"body",
wagtail.blocks.TextBlock(
help_text="Body text of the card.", required=False
),
),
(
"link_url",
wagtail.blocks.CharBlock(
help_text="Optional URL that this card should link out to. (Note: If left blank, link will not render.) ",
required=False,
),
),
(
"link_label",
wagtail.blocks.CharBlock(
help_text="Optional Label for the URL link above. (Note: If left blank, link will not render.) ",
required=False,
),
),
]
),
help_text="Please use a minimum of 2 cards.",
),
),
]
),
),
],
use_json_field=True,
),
Expand Down
2 changes: 1 addition & 1 deletion network-api/networkapi/mozfest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MozfestPrimaryPage(FoundationMetadataPageMixin, FoundationBannerInheritanc
("tito_widget", customblocks.TitoWidgetBlock()),
("tabbed_profile_directory", customblocks.TabbedProfileDirectory()),
("newsletter_signup", customblocks.NewsletterSignupBlock()),
("card_grid", mozfest_blocks.MozfestCardGridBlock()),
("mozfest_card_grid", mozfest_blocks.MozfestCardGridBlock()),
],
use_json_field=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% load wagtailcore_tags wagtailimages_tags %}

{% block block_content %}
<h3>{{ self.heading }}</h3>
<div class="tw-row">
{% for block in self.cards %}
{% with card=block count=self.cards|length %}
Expand Down
20 changes: 20 additions & 0 deletions network-api/networkapi/utility/faker/streamfield_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,25 @@ def generate_card_grid_field():
return generate_field("card_grid", {"cards": cards})


def generate_mozfest_card_grid_field():
heading = fake.sentence(nb_words=4, variable_nb_words=True)

cards = []

for n in range(2):
cards.append(
{
"image": choice(Image.objects.all()).id,
"title": fake.paragraph(nb_sentences=1, variable_nb_sentences=False),
"body": fake.paragraph(nb_sentences=10, variable_nb_sentences=True),
"link_label": " ".join(fake.words(nb=3)),
"link_url": fake.url(schemes=["https"]),
}
)

return generate_field("mozfest_card_grid", {"cards": cards, "heading": heading})


def generate_pulse_listing_field():
return generate_field(
"pulse_listing",
Expand Down Expand Up @@ -511,6 +530,7 @@ def streamfield(self, fields=None):
"current_events_slider": generate_current_events_slider_field,
"callout_box": generate_blog_index_callout_box_field,
"blog_newsletter_signup": generate_blog_newsletter_signup_field,
"mozfest_card_grid": generate_mozfest_card_grid_field,
}

streamfield_data = []
Expand Down

0 comments on commit f58ce52

Please sign in to comment.