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

adds polls and surveys from index pages to home page featured content #673

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Merge branch 'unicef-develop' into enh/add-polls-surveys-to-featured-…
…content
  • Loading branch information
sheralim012 committed Oct 25, 2021
commit 692400a78df21c0619b7659b19681adcd0ce6604
67 changes: 51 additions & 16 deletions iogt_content_migration/management/commands/load_v1_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,22 +1177,57 @@ def migrate_featured_articles_for_section(self):
self.stdout.write('Articles featured in sections migrated')

def migrate_featured_articles_for_homepage(self):
cur = self.db_query(f'select * from core_articlepage where featured_in_homepage = true')
for row in cur:
v2_article = self.v1_to_v2_page_map.get(row['page_ptr_id'])
if v2_article:
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({
'type': 'article',
'value': hfc.value.id,
})
home_featured_content.append({'type': 'article', 'value': v2_article.id})
home_page.home_featured_content = json.dumps(home_featured_content)
home_page.save()
cur.close()
self.stdout.write('Articles featured in home page migrated')
locale_cur = self.db_query(f"select * from core_sitelanguage")
for locale_row in locale_cur:
articles_cur = self.db_query(
f"select * "
f"from core_articlepage cap, wagtailcore_page wcp, core_languagerelation clr, core_sitelanguage csl "
f"where cap.page_ptr_id = wcp.id "
f"and wcp.id = clr.page_id "
f"and clr.language_id = csl.id "
f"and wcp.live = true "
f"and csl.locale = '{locale_row['locale']}' "
f"order by left(wcp.path, 16) "
)
articles_list = []
for article_row in articles_cur:
translated_from_page_id = self.page_translation_map.get(article_row['page_ptr_id'])
if translated_from_page_id:
eng_article_cur = self.db_query(
f'select * from core_articlepage where page_ptr_id = {translated_from_page_id}')
eng_article_row = eng_article_cur.fetchone()
eng_article_cur.close()
else:
eng_article_row = {'featured_in_homepage_start_date': None}

featured_in_homepage_start_date = (
article_row['featured_in_homepage_start_date'] or
eng_article_row['featured_in_homepage_start_date']
)

if featured_in_homepage_start_date:
article = self.v1_to_v2_page_map.get(article_row['page_ptr_id'])
if article:
article.featured_in_homepage_start_date = featured_in_homepage_start_date
articles_list.append(article)

articles_cur.close()

articles_list = sorted(articles_list, key=lambda x: x.featured_in_homepage_start_date, reverse=True)
for article in sorted(articles_list, key=lambda x: x.path[:16]):
self.add_article_as_featured_content_in_home_page(article)

locale_cur.close()

def add_article_as_featured_content_in_home_page(self, article):
home_page = self.home_page.get_translation_or_none(article.locale)
if home_page:
home_featured_content = home_page.home_featured_content.stream_data
home_featured_content.append({
'type': 'article',
'value': article.id,
})
home_page.save()

def attach_banners_to_home_page(self):
sql = "select * " \
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.