Skip to content

Commit

Permalink
adds polls and surveys from index pages to home page featured content
Browse files Browse the repository at this point in the history
  • Loading branch information
sheralim012 committed Oct 20, 2021
1 parent ba74869 commit 03cdc54
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
6 changes: 5 additions & 1 deletion home/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ def render_basic(self, value, context=None):
'result_as_percentage': value.result_as_percentage,
})
else:
template = 'blocks/embedded_questionnaire.html'
if value.direct_display:
template = 'blocks/embedded_questionnaire.html'
else:
template = 'blocks/questionnaire_card.html'

paginator = SkipLogicPaginator(value.get_form_fields(), {}, {})
step = paginator.page(1)
if hasattr(value, 'multi_step') and value.multi_step:
Expand Down
20 changes: 20 additions & 0 deletions home/templates/blocks/questionnaire_card.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% load static wagtailcore_tags wagtailimages_tags questionnaires_tags i18n %}


<section class="questionnaire-components">
<section class="questionnaire-components__component" style="color:#E24256;background-color:#f0f0f0">
<a href="{% pageurl page %}">
<span class='quiz__details'>
<p>{% translate page.get_type|upper %}</p>
<p>{{ page.title }}</p>
{% include 'questionnaires/index_page_description_lines.html' with page=page %}
</span>
<div class="quiz__imageholder">
<svg width="6" height="10" viewBox="0 0 6 10" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1 9L5 5.00033L1 1" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
</a>
</section>
</section>

46 changes: 41 additions & 5 deletions iogt_content_migration/management/commands/load_v1_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ def migrate(self, root):
self.migrate_media()
self.migrate_images()
self.load_page_translation_map()
home = self.create_home_page(root)
self.translate_home_pages(home)
self.create_index_pages(home)
self.home_page = self.create_home_page(root)
self.translate_home_pages(self.home_page)
self.create_index_pages(self.home_page)
self.migrate_sections()
self.migrate_articles()
self.migrate_footers()
Expand All @@ -157,6 +157,8 @@ def migrate(self, root):
self.migrate_recommended_articles_for_article()
self.migrate_featured_articles_for_section()
self.migrate_featured_articles_for_homepage()
self.add_polls_from_polls_index_page_to_home_page_featured_content()
self.add_surveys_from_surveys_index_page_to_home_page_featured_content()
self.stop_translations()

def create_home_page(self, root):
Expand Down Expand Up @@ -1143,7 +1145,7 @@ def migrate_featured_articles_for_homepage(self):
for row in cur:
v2_article = self.v1_to_v2_page_map.get(row['page_ptr_id'])
if v2_article:
home_page = v2_article.get_ancestors().exact_type(models.HomePage).first().specific
home_page = self.home_page.get_translation_or_none(v2_article.locale)
home_featured_content = []
for hfc in home_page.home_featured_content:
home_featured_content.append({
Expand Down Expand Up @@ -1173,7 +1175,6 @@ def attach_banners_to_home_page(self):
models.HomePageBanner.objects.create(source=home_page, banner_page=v2_banner)
cur.close()


def get_color_hex(self, color_name):
return {
'--tiber': '#07292F',
Expand Down Expand Up @@ -1298,3 +1299,38 @@ def fix_banner_link_page(self):
v2_banner.save()
cur.close()

def add_polls_from_polls_index_page_to_home_page_featured_content(self):
self.poll_index_page.refresh_from_db()
self.home_page.refresh_from_db()
poll_index_pages = self.poll_index_page.get_translations(inclusive=True)
for poll_index_page in poll_index_pages:
home_page = self.home_page.get_translation_or_none(poll_index_page.locale)
home_featured_content = home_page.home_featured_content.stream_data
polls = poll_index_page.get_children().live()
for poll in polls:
home_featured_content.append({
'type': 'embedded_poll',
'value': poll.id,
})
home_page.home_featured_content = json.dumps(home_featured_content)
home_page.save()

self.stdout.write('Added polls from poll index page to home page featured content.')

def add_surveys_from_surveys_index_page_to_home_page_featured_content(self):
self.survey_index_page.refresh_from_db()
self.home_page.refresh_from_db()
survey_index_pages = self.survey_index_page.get_translations(inclusive=True)
for survey_index_page in survey_index_pages:
home_page = self.home_page.get_translation_or_none(survey_index_page.locale)
home_featured_content = home_page.home_featured_content.stream_data
surveys = survey_index_page.get_children().live()
for survey in surveys:
home_featured_content.append({
'type': 'embedded_survey',
'value': survey.id,
})
home_page.home_featured_content = json.dumps(home_featured_content)
home_page.save()

self.stdout.write('Added surveys from survey index page to home page featured content.')

0 comments on commit 03cdc54

Please sign in to comment.