Fix contact CTA repair page discovery
This commit is contained in:
@@ -67,40 +67,34 @@ class Command(BaseCommand):
|
|||||||
raise CommandError(f"Page id={page_id} not found")
|
raise CommandError(f"Page id={page_id} not found")
|
||||||
self._fix_page(page, apply_changes=apply_changes)
|
self._fix_page(page, apply_changes=apply_changes)
|
||||||
else:
|
else:
|
||||||
source = self._find_contact_source_page()
|
any_found = False
|
||||||
if source is None:
|
for page in self._iter_contact_pages():
|
||||||
raise CommandError("Could not find a source contact page")
|
any_found = True
|
||||||
|
|
||||||
for locale in Locale.objects.all().order_by("language_code"):
|
|
||||||
page = (
|
|
||||||
Page.objects.filter(
|
|
||||||
translation_key=source.translation_key,
|
|
||||||
locale=locale,
|
|
||||||
)
|
|
||||||
.specific()
|
|
||||||
.first()
|
|
||||||
)
|
|
||||||
if page is None:
|
|
||||||
self.stdout.write(
|
|
||||||
f"SKIP {locale.language_code}: no contact translation"
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
self._fix_page(page, apply_changes=apply_changes)
|
self._fix_page(page, apply_changes=apply_changes)
|
||||||
|
if not any_found:
|
||||||
|
raise CommandError("Could not find any localized contact pages")
|
||||||
|
|
||||||
if not apply_changes:
|
if not apply_changes:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
"Dry-run complete. Re-run with --apply to persist changes."
|
"Dry-run complete. Re-run with --apply to persist changes."
|
||||||
)
|
)
|
||||||
|
|
||||||
def _find_contact_source_page(self) -> Page | None:
|
def _iter_contact_pages(self):
|
||||||
|
yielded = False
|
||||||
for code, slug in CONTACT_SLUGS.items():
|
for code, slug in CONTACT_SLUGS.items():
|
||||||
locale = Locale.objects.filter(language_code=code).first()
|
locale = Locale.objects.filter(language_code=code).first()
|
||||||
if locale is None:
|
if locale is None:
|
||||||
|
self.stdout.write(f"SKIP {code}: locale not found")
|
||||||
continue
|
continue
|
||||||
page = Page.objects.filter(locale=locale, slug=slug).specific().first()
|
pages = list(Page.objects.filter(locale=locale, slug=slug).specific())
|
||||||
if page is not None:
|
if not pages:
|
||||||
return page
|
self.stdout.write(f"SKIP {code}: no contact page for slug={slug}")
|
||||||
return None
|
continue
|
||||||
|
for page in pages:
|
||||||
|
yielded = True
|
||||||
|
yield page
|
||||||
|
if not yielded:
|
||||||
|
return
|
||||||
|
|
||||||
def _fix_page(self, page: Page, *, apply_changes: bool) -> None:
|
def _fix_page(self, page: Page, *, apply_changes: bool) -> None:
|
||||||
specific = page.specific
|
specific = page.specific
|
||||||
|
|||||||
Reference in New Issue
Block a user