def generate(seed): participate_page = None try: participate_page = ParticipatePage2.objects.get( title='What you can do') except WagtailPage.DoesNotExist: print( 'Participate page must exist. Ensure that ' + 'networkapi.wagtailpages.factory.participage_page is executing first' ) reseed(seed) print('Generating Participate Highlights') if participate_page is not None: featured_highlights = [HighlightFactory.create() for i in range(3)] participate_page.featured_highlights = [ ParticipatePage2FeaturedHighlightsFactory.build( highlight=featured_highlights[i]) for i in range(3) ] featured_highlights2 = [HighlightFactory.create() for i in range(6)] participate_page.featured_highlights2 = [ ParticipatePage2FeaturedHighlights2Factory.build( highlight=featured_highlights2[i]) for i in range(6) ] participate_page.save()
def setUp(self): """ Generate some highlights """ self.factory = APIRequestFactory() # Generate two default highlights self.highlights = [HighlightFactory() for i in range(2)] # Generate some highlights with specific traits self.highlights.append(HighlightFactory(has_expiry=True)) self.highlights.append( HighlightFactory(has_expiry=True, unpublished=True)) self.highlights.append(HighlightFactory(unpublished=True)) self.highlights.append(HighlightFactory(expired=True))
def test_highlight_creation(self): """ Creation a Highlight with HighlightFactory should not raise an exception """ HighlightFactory()
def test_highlight_default_expiry(self): """ By Default, a highlight should not have an expiry date """ highlight = HighlightFactory() self.assertIsNone(highlight.expires)
def test_highlight_expired_param(self): """ The expired kwargs should set the expires date to sometime in the past """ highlight = HighlightFactory(expired=True) now = datetime.now(tz=timezone.utc) self.assertLess(highlight.expires, now)
def test_highlight_default_publish_date(self): """ By Default, a highlight should have been published """ highlight = HighlightFactory() now = datetime.now(tz=timezone.utc) self.assertLess(highlight.publish_after, now)
def test_highlight_has_expiry_param(self): """ The has_expiry kwargs should set the expires date to sometime in the future """ highlight = HighlightFactory(has_expiry=True) now = datetime.now(tz=timezone.utc) self.assertGreater(highlight.expires, now)
def test_highlight_unpublished_param(self): """ The unpublished kwargs should set publish_after date to sometime in the future """ highlight = HighlightFactory(unpublished=True) now = datetime.now(tz=timezone.utc) self.assertGreater(highlight.publish_after, now)
def test_view_expired_highlight(self): """ Make sure that an expired highlight isn't accessible """ pk = HighlightFactory(expired=True) request = self.factory.get('/api/highlights/{}'.format(pk)) response = HighlightView.as_view()(request, pk=pk) self.assertEqual(response.status_code, 404)
def test_view_highlight(self): """ Make sure single highlight view returns a 200 status code """ pk = HighlightFactory().id request = self.factory.get('/api/highlights/{}'.format(pk)) response = HighlightView.as_view()(request, pk=pk) self.assertEqual(response.status_code, 200)
def generate(seed): print('Generating Homepage Highlights and News') home_page = get_homepage() reseed(seed) featured_highlights = [HighlightFactory.create() for i in range(6)] featured_news = [NewsFactory.create() for i in range(6)] home_page.featured_highlights = [ HomepageFeaturedHighlightsFactory.build( highlight=featured_highlights[i]) for i in range(6) ] home_page.featured_news = [ HomepageFeaturedNewsFactory.build(news=featured_news[i]) for i in range(6) ] home_page.save()
def generate(seed): print('Generating Homepage Blogs and Highlights') home_page = get_homepage() reseed(seed) NUM_BLOGS = 4 NUM_HIGHLIGHTS = 5 home_page.featured_blogs = [ HomepageFeaturedBlogsFactory.build(blog=BlogPage.objects.all()[i]) for i in range(NUM_BLOGS) ] home_page.featured_highlights = [ HomepageFeaturedHighlightsFactory.build( highlight=HighlightFactory.create()) for i in range(NUM_HIGHLIGHTS) ] home_page.save()
def handle(self, *args, **options): if options['delete']: call_command('flush_models') # Seed Faker with the provided seed value or a pseudorandom int between 0 and five million if options['seed']: seed = options['seed'] elif settings.RANDOM_SEED is not None: seed = settings.RANDOM_SEED else: seed = random.randint(0, 5000000) print(f'Seeding random numbers with: {seed}') random.seed(seed) faker = factory.faker.Faker._get_faker(locale='en-US') faker.random.seed(seed) print('Generating Images') [ ImageFactory.create( file__width=1080, file__height=720, file__color=faker.safe_color_name() ) for i in range(20) ] print('Generating Milestones') [MilestoneFactory.create() for i in range(10)] print('Generating five InternetHealthIssue') [InternetHealthIssue.objects.get_or_create(name=e) for e in internet_health_issues] print('Generating Fake News') generate_fake_data(NewsFactory, 10) print('Generating highlights') generate_fake_data(HighlightFactory, 4) print('Generating People') generate_fake_data(PersonFactory, 10) print('Generating People with affiliation') generate_fake_data(AffiliationFactory, 10) print('Generating blank Homepage') try: home_page = wagtailpages_models.Homepage.objects.get(title='Homepage') print('Homepage already exists') except wagtailpages_models.Homepage.DoesNotExist: print('Generating a Homepage') site_root = WagtailPage.objects.get(id=1) home_page = WagtailHomepageFactory.create( parent=site_root, title='Homepage', slug=None, hero_image__file__width=1080, hero_image__file__height=720 ) print('Generating Homepage Highlights and News') if home_page is not None: featured_news = [NewsFactory.create() for i in range(6)] featured_highlights = [HighlightFactory.create() for i in range(6)] home_page.featured_news = [ HomepageFeaturedNewsFactory.build(news=featured_news[i]) for i in range(6) ] home_page.featured_highlights = [ HomepageFeaturedHighlightsFactory.build(highlight=featured_highlights[i]) for i in range(6) ] home_page.save() try: default_site = WagtailSite.objects.get(is_default_site=True) if settings.HEROKU_APP_NAME: default_site.hostname = REVIEW_APP_HOSTNAME default_site.root_page = home_page default_site.save() print('Updated the default Site') except WagtailSite.DoesNotExist: print('Generating a default Site') if settings.HEROKU_APP_NAME: hostname = REVIEW_APP_HOSTNAME port = 80 else: hostname = 'localhost' port = 8000 WagtailSite.objects.create( hostname=hostname, port=port, root_page=home_page, site_name='Foundation Home Page', is_default_site=True ) try: about_page = WagtailPage.objects.get(title='about') print('about page exists') except WagtailPage.DoesNotExist: print('Generating an about Page (PrimaryPage)') about_page = PrimaryPageFactory.create(parent=home_page, title='about') print('Generating child pages for about page') [PrimaryPageFactory.create(parent=about_page) for i in range(5)] try: WagtailPage.objects.get(title='styleguide') print('styleguide page exists') except WagtailPage.DoesNotExist: print('Generating a Styleguide Page') StyleguideFactory.create(parent=home_page) try: WagtailPage.objects.get(title='people') print('people page exists') except WagtailPage.DoesNotExist: print('Generating an empty People Page') PeoplePageFactory.create(parent=home_page) try: WagtailPage.objects.get(title='news') print('news page exists') except WagtailPage.DoesNotExist: print('Generating an empty News Page') NewsPageFactory.create(parent=home_page) try: WagtailPage.objects.get(title='initiatives') print('initiatives page exists') except WagtailPage.DoesNotExist: print('Generating an empty Initiatives Page') InitiativesPageFactory.create(parent=home_page) try: participate_page = WagtailPage.objects.get(title='participate') print('participate page exists') except WagtailPage.DoesNotExist: print('Generating an empty Participate Page') participate_page = ParticipatePage2Factory.create(parent=home_page) print('Generating Participate Highlights') if participate_page is not None: featured_highlights = [HighlightFactory.create() for i in range(3)] participate_page.featured_highlights = [ ParticipatePage2FeaturedHighlightsFactory.build(highlight=featured_highlights[i]) for i in range(3) ] featured_highlights2 = [HighlightFactory.create() for i in range(6)] participate_page.featured_highlights2 = [ ParticipatePage2FeaturedHighlights2Factory.build(highlight=featured_highlights2[i]) for i in range(6) ] participate_page.save() try: campaign_namespace = WagtailPage.objects.get(title='campaigns') print('campaigns namespace exists') except WagtailPage.DoesNotExist: print('Generating a campaigns namespace') campaign_namespace = MiniSiteNameSpaceFactory.create(parent=home_page, title='campaigns', live=False) print('Generating Campaign Pages under namespace') campaigns = [CampaignPageFactory.create(parent=campaign_namespace) for i in range(5)] print('Generating Donation Modals for Campaign Pages') [DonationModalsFactory.create(page=campaign) for campaign in campaigns] try: wagtailpages_models.CampaignPage.objects.get(title='single-page') print('single-page CampaignPage already exists') except wagtailpages_models.CampaignPage.DoesNotExist: print('Generating single-page CampaignPage') CampaignPageFactory.create(parent=campaign_namespace, title='single-page') try: wagtailpages_models.CampaignPage.objects.get(title='multi-page') print('multi-page CampaignPage already exists.') except wagtailpages_models.CampaignPage.DoesNotExist: print('Generating multi-page CampaignPage') multi_page_campaign = CampaignPageFactory(parent=campaign_namespace, title='multi-page') [CampaignPageFactory(parent=multi_page_campaign, no_cta=True) for k in range(3)] try: opportunity_namespace = WagtailPage.objects.get(title='opportunity') print('opportunity namespace exists') except WagtailPage.DoesNotExist: print('Generating an opportunity namespace') opportunity_namespace = MiniSiteNameSpaceFactory.create(parent=home_page, title='opportunity', live=False) print('Generating Opportunity Pages under namespace') [OpportunityPageFactory.create(parent=opportunity_namespace) for i in range(5)] try: wagtailpages_models.OpportunityPage.objects.get(title='Global Sprint') print('Global Sprint OpportunityPage exists') except wagtailpages_models.OpportunityPage.DoesNotExist: print('Generating Global Sprint OpportunityPage') OpportunityPageFactory.create(parent=opportunity_namespace, title='Global Sprint', no_cta=True) try: wagtailpages_models.OpportunityPage.objects.get(title='single-page') print('single-page OpportunityPage exists') except wagtailpages_models.OpportunityPage.DoesNotExist: print('Generating single-page OpportunityPage') OpportunityPageFactory.create(parent=opportunity_namespace, title='single-page') try: wagtailpages_models.OpportunityPage.objects.get(title='multi-page') print('multi-page OpportunityPage exists') except wagtailpages_models.OpportunityPage.DoesNotExist: print('Generating multi-page OpportunityPage') multi_page_opportunity = OpportunityPageFactory(parent=opportunity_namespace, title='multi-page') [OpportunityPageFactory(parent=multi_page_opportunity, no_cta=True) for k in range(3)] print('Generating Buyer\'s Guide Products') generate_fake_data(ProductFactory, 70) print('Generating Randomised Buyer\'s Guide Products Votes') for p in Product.objects.all(): for _ in range(1, 15): value = random.randint(1, 100) RangeVote.objects.create( product=p, attribute='creepiness', value=value ) value = random.randint(1, 100) < 50 BooleanVote.objects.create( product=p, attribute='confidence', value=value ) print('Aggregating Buyer\'s Guide Product votes') call_command('aggregate_product_votes') print(self.style.SUCCESS('Done!'))
def handle(self, *args, **options): if options['delete']: call_command('flush_models') # Seed Faker with the provided seed value or a pseudorandom int between 0 and five million if options['seed']: seed = options['seed'] else: seed = randint(0, 5000000) self.stdout.write('Seeding Faker with: {}'.format(seed)) faker = factory.faker.Faker._get_faker(locale='en-US') faker.random.seed(seed) self.stdout.write('Generating LandingPage objects') opportunity = LandingPageFactory.create( title='Opportunity', content='A placeholder, this is.') [LandingPageFactory.create(parent=opportunity) for i in range(5)] self.stdout.write('Generating LandingPage objects with Signup CTAs') [ LandingPageFactory.create(parent=opportunity, signup=SignupFactory.create()) for i in range(5) ] self.stdout.write('Generating CampaignPage objects') campaigns = LandingPageFactory.create(title='Campaigns', content='Placeholder page') [CampaignFactory.create(parent=campaigns) for i in range(3)] self.stdout.write('Generating Homepage') homepage = HomepageFactory.create() self.stdout.write( 'Generating HomepageNews, HomepageHighlights, and HomepageLeaders objects' ) [HomepageNewsFactory.create(homepage=homepage) for i in range(4)] [HomepageHighlightsFactory.create(homepage=homepage) for i in range(4)] [HomepageLeadersFactory.create(homepage=homepage) for i in range(4)] self.stdout.write('Generating Highlight objects') [HighlightFactory.create() for i in range(10)] self.stdout.write('Generating Milestone objects') [MilestoneFactory.create() for i in range(10)] self.stdout.write('Generating News objects') [NewsFactory.create() for i in range(10)] self.stdout.write('Generating five InternetHealthIssue objects') issue_objects = [] for issue in internet_health_issues: issue_objects.append(InternetHealthIssueFactory(name=issue)) self.stdout.write('Generating Person and Affiliation objects') for i in range(10): person = PersonFactory.create(internet_health_issues=issue_objects) for j in range(3): AffiliationFactory.create(person=person) self.stdout.write( 'Generating unpublished, expired, and expiring highlights') [HighlightFactory.create(unpublished=True) for i in range(4)] [HighlightFactory.create(expired=True) for i in range(4)] [HighlightFactory.create(has_expiry=True) for i in range(4)] self.stdout.write('Generating unpublished, expired, and expiring News') [NewsFactory.create(unpublished=True) for i in range(4)] [NewsFactory.create(expired=True) for i in range(4)] [NewsFactory.create(has_expiry=True) for i in range(4)] [NewsFactory.create(is_video=True) for i in range(4)] self.stdout.write( 'Generating featured, unpublished, expired, and expiring People') [PersonFactory.create(is_featured=True) for i in range(4)] [PersonFactory.create(unpublished=True) for i in range(4)] [PersonFactory.create(has_expiry=True) for i in range(4)] [PersonFactory.create(expired=True) for i in range(4)] self.stdout.write(self.style.SUCCESS('Done!'))
def handle(self, *args, **options): if options['delete']: call_command('flush_models') # Seed Faker with the provided seed value or a pseudorandom int between 0 and five million if options['seed']: seed = options['seed'] elif settings.RANDOM_SEED is not None: seed = settings.RANDOM_SEED else: seed = random.randint(0, 5000000) faker = factory.faker.Faker._get_faker(locale='en-US') def reseed(): random.seed(seed) faker.random.seed(seed) print(f'Seeding random numbers with: {seed}') reseed() print('Generating Images') [ ImageFactory.create(file__width=1080, file__height=720, file__color=faker.safe_color_name()) for i in range(20) ] reseed() print('Generating Milestones') [MilestoneFactory.create() for i in range(10)] reseed() print('Generating five InternetHealthIssue') [ InternetHealthIssue.objects.get_or_create(name=e) for e in internet_health_issues ] reseed() print('Generating Fake News') generate_fake_data(NewsFactory, 10) reseed() print('Generating highlights') generate_fake_data(HighlightFactory, 4) reseed() print('Generating People') generate_fake_data(PersonFactory, 10) reseed() print('Generating People with affiliation') generate_fake_data(AffiliationFactory, 10) reseed() print('Generating blank Homepage') try: home_page = wagtailpages_models.Homepage.objects.get( title='Homepage') print('Homepage already exists') except wagtailpages_models.Homepage.DoesNotExist: print('Generating a Homepage') site_root = WagtailPage.objects.get(id=1) home_page = WagtailHomepageFactory.create( parent=site_root, title='Homepage', slug=None, hero_image__file__width=1080, hero_image__file__height=720) reseed() print('Generating Homepage Highlights and News') if home_page is not None: featured_news = [NewsFactory.create() for i in range(6)] featured_highlights = [HighlightFactory.create() for i in range(6)] home_page.featured_news = [ HomepageFeaturedNewsFactory.build(news=featured_news[i]) for i in range(6) ] home_page.featured_highlights = [ HomepageFeaturedHighlightsFactory.build( highlight=featured_highlights[i]) for i in range(6) ] home_page.save() reseed() try: default_site = WagtailSite.objects.get(is_default_site=True) if settings.HEROKU_APP_NAME: default_site.hostname = REVIEW_APP_HOSTNAME default_site.root_page = home_page default_site.save() print('Updated the default Site') except WagtailSite.DoesNotExist: print('Generating a default Site') if settings.HEROKU_APP_NAME: hostname = REVIEW_APP_HOSTNAME port = 80 else: hostname = 'localhost' port = 8000 WagtailSite.objects.create(hostname=hostname, port=port, root_page=home_page, site_name='Foundation Home Page', is_default_site=True) reseed() try: about_page = WagtailPage.objects.get(title='about') print('about page exists') except WagtailPage.DoesNotExist: print('Generating an about Page (PrimaryPage)') about_page = PrimaryPageFactory.create(parent=home_page, title='about') reseed() print('Generating child pages for about page') [PrimaryPageFactory.create(parent=about_page) for i in range(5)] reseed() try: WagtailPage.objects.get(title='styleguide') print('styleguide page exists') except WagtailPage.DoesNotExist: print('Generating a Styleguide Page') StyleguideFactory.create(parent=home_page) reseed() try: WagtailPage.objects.get(title='people') print('people page exists') except WagtailPage.DoesNotExist: print('Generating an empty People Page') PeoplePageFactory.create(parent=home_page) reseed() try: WagtailPage.objects.get(title='news') print('news page exists') except WagtailPage.DoesNotExist: print('Generating an empty News Page') NewsPageFactory.create(parent=home_page) reseed() try: WagtailPage.objects.get(title='initiatives') print('initiatives page exists') except WagtailPage.DoesNotExist: print('Generating an empty Initiatives Page') InitiativesPageFactory.create(parent=home_page) reseed() try: participate_page = WagtailPage.objects.get(title='participate') print('participate page exists') except WagtailPage.DoesNotExist: print('Generating an empty Participate Page') participate_page = ParticipatePage2Factory.create(parent=home_page) reseed() print('Generating Participate Highlights') if participate_page is not None: featured_highlights = [HighlightFactory.create() for i in range(3)] participate_page.featured_highlights = [ ParticipatePage2FeaturedHighlightsFactory.build( highlight=featured_highlights[i]) for i in range(3) ] featured_highlights2 = [ HighlightFactory.create() for i in range(6) ] participate_page.featured_highlights2 = [ ParticipatePage2FeaturedHighlights2Factory.build( highlight=featured_highlights2[i]) for i in range(6) ] participate_page.save() reseed() try: campaign_namespace = WagtailPage.objects.get(title='campaigns') print('campaigns namespace exists') except WagtailPage.DoesNotExist: print('Generating a campaigns namespace') campaign_namespace = MiniSiteNameSpaceFactory.create( parent=home_page, title='campaigns', live=False) reseed() print('Generating Campaign Pages under namespace') campaigns = [ CampaignPageFactory.create(parent=campaign_namespace) for i in range(5) ] reseed() print('Generating Donation Modals for Campaign Pages') [DonationModalsFactory.create(page=campaign) for campaign in campaigns] reseed() try: wagtailpages_models.CampaignPage.objects.get(title='single-page') print('single-page CampaignPage already exists') except wagtailpages_models.CampaignPage.DoesNotExist: print('Generating single-page CampaignPage') CampaignPageFactory.create(parent=campaign_namespace, title='single-page') reseed() try: wagtailpages_models.CampaignPage.objects.get(title='multi-page') print('multi-page CampaignPage already exists.') except wagtailpages_models.CampaignPage.DoesNotExist: print('Generating multi-page CampaignPage') multi_page_campaign = CampaignPageFactory( parent=campaign_namespace, title='multi-page') [CampaignPageFactory(parent=multi_page_campaign) for k in range(3)] reseed() try: opportunity_namespace = WagtailPage.objects.get( title='opportunity') print('opportunity namespace exists') except WagtailPage.DoesNotExist: print('Generating an opportunity namespace') opportunity_namespace = MiniSiteNameSpaceFactory.create( parent=home_page, title='opportunity', live=False) reseed() print('Generating Opportunity Pages under namespace') [ OpportunityPageFactory.create(parent=opportunity_namespace) for i in range(5) ] reseed() try: wagtailpages_models.OpportunityPage.objects.get( title='Global Sprint') print('Global Sprint OpportunityPage exists') except wagtailpages_models.OpportunityPage.DoesNotExist: print('Generating Global Sprint OpportunityPage') OpportunityPageFactory.create(parent=opportunity_namespace, title='Global Sprint') reseed() try: wagtailpages_models.OpportunityPage.objects.get( title='single-page') print('single-page OpportunityPage exists') except wagtailpages_models.OpportunityPage.DoesNotExist: print('Generating single-page OpportunityPage') OpportunityPageFactory.create(parent=opportunity_namespace, title='single-page') reseed() try: wagtailpages_models.OpportunityPage.objects.get(title='multi-page') print('multi-page OpportunityPage exists') except wagtailpages_models.OpportunityPage.DoesNotExist: print('Generating multi-page OpportunityPage') multi_page_opportunity = OpportunityPageFactory( parent=opportunity_namespace, title='multi-page') [ OpportunityPageFactory(parent=multi_page_opportunity) for k in range(3) ] reseed() print( 'Generating fixed Buyer\'s Guide Product for visual regression testing' ) ProductFactory.create( product_words=['Percy', 'Cypress'], name='percy cypress', draft=False, adult_content=False, company='Percy', blurb='Visual Regression Testing', url='https://vrt.example.com', price=350, camera_app=True, meets_minimum_security_standards=True, camera_device=False, microphone_app=True, microphone_device=False, location_app=True, location_device=False, uses_encryption=True, privacy_policy_reading_level_url='https://vrt.example.com/pprl', privacy_policy_reading_level='7', share_data=False, must_change_default_password=False, security_updates=False, delete_data=True, child_rules=False, manage_security=True, phone_number='1-555-555-5555', live_chat=True, email='*****@*****.**', worst_case='Duplicate work that burns through screenshots', ) reseed() print('Generating Buyer\'s Guide Products') generate_fake_data(ProductFactory, 70) reseed() print('Generating Randomised Buyer\'s Guide Products Votes') for p in Product.objects.all(): for _ in range(1, 15): value = random.randint(1, 100) RangeVote.objects.create(product=p, attribute='creepiness', value=value) value = random.randint(1, 100) < 50 BooleanVote.objects.create(product=p, attribute='confidence', value=value) reseed() print('Aggregating Buyer\'s Guide Product votes') call_command('aggregate_product_votes') print(self.style.SUCCESS('Done!'))
def handle(self, *args, **options): if options['delete']: call_command('flush_models') # Seed Faker with the provided seed value or a pseudorandom int between 0 and five million if options['seed']: seed = options['seed'] else: seed = randint(0, 5000000) print('Seeding Faker with: {}'.format(seed)) faker = factory.faker.Faker._get_faker(locale='en-US') faker.random.seed(seed) print('Generating Milestones') [MilestoneFactory.create() for i in range(10)] print('Generating five InternetHealthIssue') [ InternetHealthIssue.objects.get_or_create(name=e) for e in internet_health_issues ] print('Generating News') generate_fake_data(NewsFactory, 10) print('Generating highlights') generate_fake_data(HighlightFactory, 4) print('Generating People') generate_fake_data(PersonFactory, 10) print('Generating People with affiliation') generate_fake_data(AffiliationFactory, 10) print('Generating blank Homepage') try: home_page = wagtailpages_models.Homepage.objects.get( title='Homepage') print('Homepage already exists') except ObjectDoesNotExist: print('Generating a Homepage') site_root = WagtailPage.objects.get(title='Root') home_page = WagtailHomepageFactory.create( parent=site_root, title='Homepage', slug=None, hero_image__file__width=1080, hero_image__file__height=720) print('Generating Homepage Highlights and News') featured_news = [NewsFactory.create() for i in range(6)] featured_highlights = [HighlightFactory.create() for i in range(6)] home_page.featured_news = [ HomepageFeaturedNewsFactory.build(news=featured_news[i]) for i in range(6) ] home_page.featured_highlights = [ HomepageFeaturedHighlightsFactory.build( highlight=featured_highlights[i]) for i in range(6) ] home_page.save() try: default_site = WagtailSite.objects.get(is_default_site=True) default_site.root_page = home_page default_site.save() print('Updated the default Site') except ObjectDoesNotExist: print('Generating a default Site') WagtailSite.objects.create(hostname='localhost', port=8000, root_page=home_page, site_name='Foundation Home Page', is_default_site=True) try: about_page = WagtailPage.objects.get(title='about') print('about page exists') except ObjectDoesNotExist: print('Generating an about Page (PrimaryPage)') about_page = PrimaryPageFactory.create(parent=home_page, title='about') print('Generating child pages for about page') [PrimaryPageFactory.create(parent=about_page) for i in range(5)] try: WagtailPage.objects.get(title='styleguide') print('styleguide page exists') except ObjectDoesNotExist: print('Generating a Styleguide Page') StyleguideFactory.create(parent=home_page) try: WagtailPage.objects.get(title='people') print('people page exists') except ObjectDoesNotExist: print('Generating an empty People Page') PeoplePageFactory.create(parent=home_page) try: WagtailPage.objects.get(title='news') print('news page exists') except ObjectDoesNotExist: print('Generating an empty News Page') NewsPageFactory.create(parent=home_page) try: WagtailPage.objects.get(title='initiatives') print('initiatives page exists') except ObjectDoesNotExist: print('Generating an empty Initiatives Page') InitiativesPageFactory.create(parent=home_page) try: WagtailPage.objects.get(title='participate') print('participate page exists') except ObjectDoesNotExist: print('Generating an empty Participate Page') ParticipatePageFactory.create(parent=home_page) try: campaign_namespace = WagtailPage.objects.get(title='campaigns') print('campaigns namespace exists') except ObjectDoesNotExist: print('Generating a campaigns namespace') campaign_namespace = MiniSiteNameSpaceFactory.create( parent=home_page, title='campaigns', live=False) print('Generating Campaign Pages under namespace') [ CampaignPageFactory.create(parent=campaign_namespace) for i in range(5) ] try: wagtailpages_models.CampaignPage.objects.get(title='single-page') print('single-page CampaignPage already exists') except ObjectDoesNotExist: print('Generating single-page CampaignPage') CampaignPageFactory.create(parent=campaign_namespace, title='single-page') try: wagtailpages_models.CampaignPage.objects.get(title='multi-page') print('multi-page CampaignPage already exists.') except ObjectDoesNotExist: print('Generating multi-page CampaignPage') multi_page_campaign = CampaignPageFactory( parent=campaign_namespace, title='multi-page') [ CampaignPageFactory(parent=multi_page_campaign, no_cta=True) for k in range(3) ] try: opportunity_namespace = WagtailPage.objects.get( title='opportunity') print('opportunity namespace exists') except ObjectDoesNotExist: print('Generating an opportunity namespace') opportunity_namespace = MiniSiteNameSpaceFactory.create( parent=home_page, title='opportunity', live=False) print('Generating Opportunity Pages under namespace') [ OpportunityPageFactory.create(parent=opportunity_namespace) for i in range(5) ] try: wagtailpages_models.OpportunityPage.objects.get( title='Global Sprint') print('Global Sprint OpportunityPage exists') except ObjectDoesNotExist: print('Generating Global Sprint OpportunityPage') OpportunityPageFactory.create(parent=opportunity_namespace, title='Global Sprint', no_cta=True) try: wagtailpages_models.OpportunityPage.objects.get( title='single-page') print('single-page OpportunityPage exists') except ObjectDoesNotExist: print('Generating single-page OpportunityPage') OpportunityPageFactory.create(parent=opportunity_namespace, title='single-page') try: wagtailpages_models.OpportunityPage.objects.get(title='multi-page') print('multi-page OpportunityPage exists') except ObjectDoesNotExist: print('Generating multi-page OpportunityPage') multi_page_opportunity = OpportunityPageFactory( parent=opportunity_namespace, title='multi-page') [ OpportunityPageFactory(parent=multi_page_opportunity, no_cta=True) for k in range(3) ] print(self.style.SUCCESS('Done!'))