Skip to content
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

Feature/9282 stats block #11534

Merged
merged 7 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions network-api/networkapi/mozfest/blocks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# flake8: noqa
from .stats_block import StatisticsBlock
15 changes: 15 additions & 0 deletions network-api/networkapi/mozfest/blocks/stats_block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from wagtail import blocks


class StatisticCard(blocks.StructBlock):
title = blocks.CharBlock(help_text="The statistic figure, e.g '1000+' or '10%'")
description = blocks.CharBlock(help_text="Context or description for the statistic")


class StatisticsBlock(blocks.StructBlock):
statistics = blocks.ListBlock(StatisticCard(), help_text="Please use a minimum of 2 cards.", max_num=4, min_num=2)

class Meta:
icon = "placeholder"
template = "fragments/blocks/stats_block.html"
label = "Stats Block"
3 changes: 2 additions & 1 deletion network-api/networkapi/mozfest/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
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", "stats_block"]

Faker.add_provider(StreamfieldProvider)

is_review_app = False
Expand Down
1,646 changes: 1,646 additions & 0 deletions network-api/networkapi/mozfest/migrations/0031_adds_stats_block.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions network-api/networkapi/mozfest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from wagtail.models import Locale, Page
from wagtail_localize.fields import SynchronizedField, TranslatableField

from networkapi.mozfest import blocks as mozfest_blocks
from networkapi.wagtailpages.models import (
FoundationBannerInheritanceMixin,
FoundationMetadataPageMixin,
Expand Down Expand Up @@ -51,6 +52,7 @@ class MozfestPrimaryPage(FoundationMetadataPageMixin, FoundationBannerInheritanc
("tito_widget", customblocks.TitoWidgetBlock()),
("tabbed_profile_directory", customblocks.TabbedProfileDirectory()),
("newsletter_signup", customblocks.NewsletterSignupBlock()),
("stats_block", mozfest_blocks.StatisticsBlock()),
],
use_json_field=True,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% load wagtailcore_tags wagtailimages_tags %}

{% block block_content %}
<div class="tw-bg-black tw-dark tw-py-16">
<div class="tw-container">
<div class="tw-row">
{% for stat in self.statistics %}
<div class="tw-mb-12 tw-px-8 tw-w-1/2 large:tw-w-1/4">
<p class="tw-h1-heading tw-mb-0">{{ stat.title }}</p>
<p class="tw-my-0">{{ stat.description }}</p>
</div>
{% endfor %}
</div>
</div>
</div>
{% endblock block_content %}
23 changes: 4 additions & 19 deletions network-api/networkapi/mozfest/templates/mozfest/mozfest-base.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,10 @@
{% block content %}
{% block secondary_nav %}{% endblock %}

{% if page.signup != None %}

{# Use a two-column layout #}
<div class="container">
<div class="row">
<div class="cms mozfest-content two-col mb-5">
{% include "partials/streamfield.html" with twocolumn=True %}
</div>
{% block cta %}{% include "partials/signup.html" %}{% endblock %}
</div>
</div>
{% else %}

{# Single column layout #}
<div class="cms mozfest-content mb-3 {% if page.use_wide_template %} wide {% endif %}">
{% include "partials/streamfield.html" %}
</div>

{% endif %}
{# Single column layout #}
<div class="cms mozfest-content mb-3 {% if page.use_wide_template %} wide {% endif %}">
{% include "partials/streamfield.html" %}
</div>

{% endblock %}

Expand Down
15 changes: 15 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,20 @@ def generate_card_grid_field():
return generate_field("card_grid", {"cards": cards})


def generate_stats_block_field():
statistics = []

for n in range(4):
statistics.append(
{
"title": str(fake.pyint()),
"description": " ".join(fake.words(nb=8)),
}
)

return generate_field("stats_block", {"statistics": statistics})


def generate_pulse_listing_field():
return generate_field(
"pulse_listing",
Expand Down Expand Up @@ -511,6 +525,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,
"stats_block": generate_stats_block_field,
}

streamfield_data = []
Expand Down