From e92ed5b638cfd34c5df8352fd5b96371a9c82234 Mon Sep 17 00:00:00 2001 From: AdalbertoMoz Date: Wed, 3 Jul 2024 18:10:08 -0600 Subject: [PATCH 1/5] Feature: Add factory for AppInstallPage --- .../factory/youtube_regrets_page.py | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py b/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py index 0b0f5cdf13c..20aa7851e70 100644 --- a/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py +++ b/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py @@ -1,16 +1,20 @@ -from factory import Faker +from factory import Faker, SubFactory from wagtail.models import Page as WagtailPage from wagtail_factories import PageFactory from networkapi.utility.faker.helpers import get_homepage, reseed +from networkapi.wagtailpages.factory import image_factory from networkapi.wagtailpages.models import ( + AppInstallPage, YoutubeRegrets2021Page, YoutubeRegrets2022Page, YoutubeRegretsPage, YoutubeRegretsReporterPage, ) +from .bannered_campaign_page import BanneredCampaignPageFactory from .campaign_page import CampaignIndexPageFactory +from .petition import PetitionFactory class YoutubeRegretsPageFactory(PageFactory): @@ -30,6 +34,25 @@ class Meta: regret_stories = Faker("streamfield", fields=["regret_story"] * 28) +class AppInstallPageFactory(PageFactory): + class Meta: + model = AppInstallPage + exclude = ( + "title_text", + "header_text", + "header", + ) + + title = "Regrets Reporter Page" + slug = "regretsreporter" + hero_heading = Faker("text", max_nb_chars=50) + hero_subheading = Faker("text", max_nb_chars=50) + hero_background = SubFactory(image_factory.ImageFactory) + hero_video = Faker("url") + cta = SubFactory(PetitionFactory) + body = Faker("streamfield", fields=["header", "paragraph", "image", "spacer", "image_text", "quote"]) + + class YoutubeRegrets2021PageFactory(PageFactory): class Meta: model = YoutubeRegrets2021Page @@ -109,3 +132,28 @@ def generate(seed): YoutubeRegrets2021PageFactory.create(parent=youtube_regrets) YoutubeRegrets2022PageFactory.create(parent=youtube_regrets) reseed(seed) + + # App Install Page + # Checking for a bannered campaign page titled "Youtube Regrets", and then creating the landing page if + # it does not exist. + try: + youtube_bannered_campaign_page = WagtailPage.objects.child_of(home_page).get(title=title) + print("Youtube Regrets Bannered Campaign Page exists") + # If extension landing page does not exist, create it. + if not WagtailPage.objects.child_of(youtube_bannered_campaign_page).type(AppInstallPage): + print("Generating App Install Page") + AppInstallPageFactory.create(parent=youtube_bannered_campaign_page) + + # If bannered "YouTube Regrets" campaign page does not exist, create it and the extension landing page. + except WagtailPage.DoesNotExist: + print("Generating a Youtube Bannered Campaign Page and App Install Page") + youtube_bannered_campaign_page = BanneredCampaignPageFactory.create( + parent=home_page, + title="YouTube Regrets", + slug="youtube", + show_in_menus=False, + live=True, + ) + AppInstallPageFactory.create(parent=youtube_bannered_campaign_page) + + reseed(seed) From 2efa4a80cebed3ae901fb4be2cc8fd711233466f Mon Sep 17 00:00:00 2001 From: AdalbertoMoz Date: Mon, 8 Jul 2024 19:41:57 -0600 Subject: [PATCH 2/5] Feature: Delete Video URL and add buttons for AppInstallPage --- .../utility/faker/streamfield_provider.py | 13 +++++++++++++ .../wagtailpages/factory/youtube_regrets_page.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/network-api/networkapi/utility/faker/streamfield_provider.py b/network-api/networkapi/utility/faker/streamfield_provider.py index e61730cddc7..0814b95a241 100644 --- a/network-api/networkapi/utility/faker/streamfield_provider.py +++ b/network-api/networkapi/utility/faker/streamfield_provider.py @@ -675,6 +675,18 @@ def generate_mixed_content_field(): ) +def generate_app_install_download_button_field(): + return generate_field( + "button", + { + "link_to": "external_url", + "external_url": fake.url(schemes=["https"]), + "label": " ".join(fake.words(nb=2)), + "new_window": True, + }, + ) + + class StreamfieldProvider(BaseProvider): """ A custom Faker Provider for relative image urls, for use with factory_boy @@ -734,6 +746,7 @@ def streamfield(self, fields=None): "profiles": generate_profiles_field, "newsletter_signup": generate_newsletter_signup_with_background_field, "mixed_content": generate_mixed_content_field, + "app_install_download_button": generate_app_install_download_button_field, } streamfield_data = [] diff --git a/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py b/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py index 20aa7851e70..24f9a95666f 100644 --- a/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py +++ b/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py @@ -48,7 +48,7 @@ class Meta: hero_heading = Faker("text", max_nb_chars=50) hero_subheading = Faker("text", max_nb_chars=50) hero_background = SubFactory(image_factory.ImageFactory) - hero_video = Faker("url") + download_buttons = Faker("streamfield", fields=["app_install_download_button"] * 2) cta = SubFactory(PetitionFactory) body = Faker("streamfield", fields=["header", "paragraph", "image", "spacer", "image_text", "quote"]) From 253fa4f6fad64f1c6ee1104f121eed8171ec4fd6 Mon Sep 17 00:00:00 2001 From: AdalbertoMoz Date: Mon, 8 Jul 2024 19:51:38 -0600 Subject: [PATCH 3/5] Refactor: Move AppInstallPageFactory to a separate file --- .../wagtailpages/factory/app_install_page.py | 26 +++++++++++++++++++ .../factory/youtube_regrets_page.py | 24 ++--------------- 2 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 network-api/networkapi/wagtailpages/factory/app_install_page.py diff --git a/network-api/networkapi/wagtailpages/factory/app_install_page.py b/network-api/networkapi/wagtailpages/factory/app_install_page.py new file mode 100644 index 00000000000..7d27d855043 --- /dev/null +++ b/network-api/networkapi/wagtailpages/factory/app_install_page.py @@ -0,0 +1,26 @@ +from factory import Faker, SubFactory +from wagtail_factories import PageFactory + +from networkapi.wagtailpages.factory import image_factory +from networkapi.wagtailpages.models import AppInstallPage + +from .petition import PetitionFactory + + +class AppInstallPageFactory(PageFactory): + class Meta: + model = AppInstallPage + exclude = ( + "title_text", + "header_text", + "header", + ) + + title = "Regrets Reporter Page" + slug = "regretsreporter" + hero_heading = Faker("text", max_nb_chars=50) + hero_subheading = Faker("text", max_nb_chars=50) + hero_background = SubFactory(image_factory.ImageFactory) + download_buttons = Faker("streamfield", fields=["app_install_download_button"] * 2) + cta = SubFactory(PetitionFactory) + body = Faker("streamfield", fields=["header", "paragraph", "image", "spacer", "image_text", "quote"]) diff --git a/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py b/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py index 24f9a95666f..04183b55ffe 100644 --- a/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py +++ b/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py @@ -1,9 +1,8 @@ -from factory import Faker, SubFactory +from factory import Faker from wagtail.models import Page as WagtailPage from wagtail_factories import PageFactory from networkapi.utility.faker.helpers import get_homepage, reseed -from networkapi.wagtailpages.factory import image_factory from networkapi.wagtailpages.models import ( AppInstallPage, YoutubeRegrets2021Page, @@ -12,9 +11,9 @@ YoutubeRegretsReporterPage, ) +from .app_install_page import AppInstallPageFactory from .bannered_campaign_page import BanneredCampaignPageFactory from .campaign_page import CampaignIndexPageFactory -from .petition import PetitionFactory class YoutubeRegretsPageFactory(PageFactory): @@ -34,25 +33,6 @@ class Meta: regret_stories = Faker("streamfield", fields=["regret_story"] * 28) -class AppInstallPageFactory(PageFactory): - class Meta: - model = AppInstallPage - exclude = ( - "title_text", - "header_text", - "header", - ) - - title = "Regrets Reporter Page" - slug = "regretsreporter" - hero_heading = Faker("text", max_nb_chars=50) - hero_subheading = Faker("text", max_nb_chars=50) - hero_background = SubFactory(image_factory.ImageFactory) - download_buttons = Faker("streamfield", fields=["app_install_download_button"] * 2) - cta = SubFactory(PetitionFactory) - body = Faker("streamfield", fields=["header", "paragraph", "image", "spacer", "image_text", "quote"]) - - class YoutubeRegrets2021PageFactory(PageFactory): class Meta: model = YoutubeRegrets2021Page From fb0a743a8a8725e862bd1355806d677e82907c35 Mon Sep 17 00:00:00 2001 From: AdalbertoMoz Date: Tue, 9 Jul 2024 11:41:33 -0600 Subject: [PATCH 4/5] Feature: Move AppInstallPage to it's own slug under homepage --- .../wagtailpages/factory/__init__.py | 2 ++ .../wagtailpages/factory/app_install_page.py | 13 ++++++++++ .../factory/youtube_regrets_page.py | 25 ------------------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/network-api/networkapi/wagtailpages/factory/__init__.py b/network-api/networkapi/wagtailpages/factory/__init__.py index 54c14dffa06..5b4921c214f 100644 --- a/network-api/networkapi/wagtailpages/factory/__init__.py +++ b/network-api/networkapi/wagtailpages/factory/__init__.py @@ -1,6 +1,7 @@ from networkapi.wagtailpages.factory.libraries import rcc, research_hub from . import ( + app_install_page, bannered_campaign_page, blog, buyersguide, @@ -50,6 +51,7 @@ def generate(seed): rcc.generate(seed) # homepage_cause_statement_link requires child pages of homepage to exist homepage_cause_statement_link.generate(seed) + app_install_page.generate(seed) __all__ = [ diff --git a/network-api/networkapi/wagtailpages/factory/app_install_page.py b/network-api/networkapi/wagtailpages/factory/app_install_page.py index 7d27d855043..89c442e9683 100644 --- a/network-api/networkapi/wagtailpages/factory/app_install_page.py +++ b/network-api/networkapi/wagtailpages/factory/app_install_page.py @@ -1,6 +1,8 @@ from factory import Faker, SubFactory from wagtail_factories import PageFactory +from networkapi.utility.faker.helpers import reseed +from networkapi.wagtailpages import models as pagemodels from networkapi.wagtailpages.factory import image_factory from networkapi.wagtailpages.models import AppInstallPage @@ -24,3 +26,14 @@ class Meta: download_buttons = Faker("streamfield", fields=["app_install_download_button"] * 2) cta = SubFactory(PetitionFactory) body = Faker("streamfield", fields=["header", "paragraph", "image", "spacer", "image_text", "quote"]) + + +def generate(seed): + reseed(seed) + + print("Generating PNI Homepage") + AppInstallPageFactory.create( + parent=pagemodels.Homepage.objects.first(), + title="App Install Page", + slug="app-install-page", + ) diff --git a/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py b/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py index 04183b55ffe..3c579e666dc 100644 --- a/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py +++ b/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py @@ -112,28 +112,3 @@ def generate(seed): YoutubeRegrets2021PageFactory.create(parent=youtube_regrets) YoutubeRegrets2022PageFactory.create(parent=youtube_regrets) reseed(seed) - - # App Install Page - # Checking for a bannered campaign page titled "Youtube Regrets", and then creating the landing page if - # it does not exist. - try: - youtube_bannered_campaign_page = WagtailPage.objects.child_of(home_page).get(title=title) - print("Youtube Regrets Bannered Campaign Page exists") - # If extension landing page does not exist, create it. - if not WagtailPage.objects.child_of(youtube_bannered_campaign_page).type(AppInstallPage): - print("Generating App Install Page") - AppInstallPageFactory.create(parent=youtube_bannered_campaign_page) - - # If bannered "YouTube Regrets" campaign page does not exist, create it and the extension landing page. - except WagtailPage.DoesNotExist: - print("Generating a Youtube Bannered Campaign Page and App Install Page") - youtube_bannered_campaign_page = BanneredCampaignPageFactory.create( - parent=home_page, - title="YouTube Regrets", - slug="youtube", - show_in_menus=False, - live=True, - ) - AppInstallPageFactory.create(parent=youtube_bannered_campaign_page) - - reseed(seed) From 6c112e7e72987baff7fc0109258c58bbb8d537c1 Mon Sep 17 00:00:00 2001 From: AdalbertoMoz Date: Tue, 9 Jul 2024 11:47:12 -0600 Subject: [PATCH 5/5] Refactor: Delete unused imports in youtube_regrets_poage.py --- .../networkapi/wagtailpages/factory/youtube_regrets_page.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py b/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py index 3c579e666dc..0b0f5cdf13c 100644 --- a/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py +++ b/network-api/networkapi/wagtailpages/factory/youtube_regrets_page.py @@ -4,15 +4,12 @@ from networkapi.utility.faker.helpers import get_homepage, reseed from networkapi.wagtailpages.models import ( - AppInstallPage, YoutubeRegrets2021Page, YoutubeRegrets2022Page, YoutubeRegretsPage, YoutubeRegretsReporterPage, ) -from .app_install_page import AppInstallPageFactory -from .bannered_campaign_page import BanneredCampaignPageFactory from .campaign_page import CampaignIndexPageFactory