fix: repair RU capabilities CTA note
This commit is contained in:
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@@ -186,7 +186,7 @@ PY
|
||||
steps {
|
||||
sh '''
|
||||
set -e
|
||||
REMOTE_CMD="cd '${STAGING_AUDIT_PROJECT_DIR}' && '${STAGING_AUDIT_MANAGE}' fix_no_credit_card_text --apply"
|
||||
REMOTE_CMD="cd '${STAGING_AUDIT_PROJECT_DIR}' && '${STAGING_AUDIT_MANAGE}' fix_no_credit_card_text --apply --page-id 675"
|
||||
sudo -n -u mandel -g www-data /srv/apps/mandel-dashboard/.venv/bin/python /srv/apps/mandel-dashboard/bin/deploy_stg_from_jenkins.py "${STAGING_AUDIT_PROJECT_NAME}" --command "$REMOTE_CMD"
|
||||
'''
|
||||
}
|
||||
|
||||
@@ -80,6 +80,11 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
"--page-id",
|
||||
type=int,
|
||||
help="Optional Wagtail page id to fix (overrides capabilities lookup).",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--apply",
|
||||
action="store_true",
|
||||
@@ -88,73 +93,89 @@ class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
apply_changes = options["apply"]
|
||||
|
||||
# The live issue was observed on RU "Capabilities" (mogelijkheden) translation.
|
||||
nl_locale = Locale.objects.filter(language_code="nl").first()
|
||||
if nl_locale is None:
|
||||
raise CommandError("Locale nl not found")
|
||||
|
||||
source = (
|
||||
Page.objects.filter(locale=nl_locale, slug="mogelijkheden")
|
||||
.specific()
|
||||
.first()
|
||||
)
|
||||
if source is None:
|
||||
raise CommandError("Could not find source page nl/slug=mogelijkheden")
|
||||
page_id = options.get("page_id")
|
||||
|
||||
with transaction.atomic():
|
||||
for locale in Locale.objects.all().order_by("language_code"):
|
||||
code = locale.language_code
|
||||
page = (
|
||||
Page.objects.filter(
|
||||
translation_key=source.translation_key, locale=locale
|
||||
)
|
||||
if page_id:
|
||||
page = Page.objects.filter(id=page_id).specific().first()
|
||||
if page is None:
|
||||
raise CommandError(f"Page id={page_id} not found")
|
||||
self._fix_page(page, apply_changes=apply_changes)
|
||||
else:
|
||||
nl_locale = Locale.objects.filter(language_code="nl").first()
|
||||
if nl_locale is None:
|
||||
raise CommandError("Locale nl not found")
|
||||
|
||||
source = (
|
||||
Page.objects.filter(locale=nl_locale, slug="mogelijkheden")
|
||||
.specific()
|
||||
.first()
|
||||
)
|
||||
if page is None:
|
||||
self.stdout.write(f"SKIP {code}: no translation for mogelijkheden")
|
||||
continue
|
||||
if source is None:
|
||||
raise CommandError(
|
||||
"Could not find source page nl/slug=mogelijkheden"
|
||||
)
|
||||
|
||||
specific = page.specific
|
||||
if not hasattr(specific, "body"):
|
||||
self.stdout.write(f"SKIP {code}: no body streamfield")
|
||||
continue
|
||||
|
||||
body = specific.body
|
||||
raw_data = list(body.raw_data)
|
||||
no_cc = NO_CC_TEXT.get(code) or NO_CC_TEXT["en"]
|
||||
contact_url = _localized_url(131, locale) # contact
|
||||
services_url = _localized_url(129, locale) # services
|
||||
changed = False
|
||||
for block in raw_data:
|
||||
if block.get("type") != "saas_cta_footer":
|
||||
for locale in Locale.objects.all().order_by("language_code"):
|
||||
code = locale.language_code
|
||||
page = (
|
||||
Page.objects.filter(
|
||||
translation_key=source.translation_key, locale=locale
|
||||
)
|
||||
.specific()
|
||||
.first()
|
||||
)
|
||||
if page is None:
|
||||
self.stdout.write(
|
||||
f"SKIP {code}: no translation for mogelijkheden"
|
||||
)
|
||||
continue
|
||||
value = block.get("value")
|
||||
if not isinstance(value, dict):
|
||||
continue
|
||||
if _fix_cta_footer(
|
||||
value,
|
||||
no_cc_text=no_cc,
|
||||
primary_url=contact_url,
|
||||
secondary_url=services_url,
|
||||
):
|
||||
block["value"] = value
|
||||
changed = True
|
||||
|
||||
if not changed:
|
||||
self.stdout.write(f"OK {code}: no cta footer changes needed")
|
||||
continue
|
||||
|
||||
self.stdout.write(
|
||||
f"CHG {code}: fixed saas_cta_footer no_credit_card_text/urls"
|
||||
)
|
||||
specific.body = StreamValue(body.stream_block, raw_data, is_lazy=True)
|
||||
if apply_changes:
|
||||
rev = specific.save_revision()
|
||||
rev.publish()
|
||||
self._fix_page(page, apply_changes=apply_changes)
|
||||
|
||||
if not apply_changes:
|
||||
raise CommandError(
|
||||
"Dry-run complete. Re-run with --apply to persist changes."
|
||||
)
|
||||
|
||||
def _fix_page(self, page: Page, *, apply_changes: bool) -> None:
|
||||
locale = page.locale
|
||||
code = locale.language_code
|
||||
|
||||
specific = page.specific
|
||||
if not hasattr(specific, "body"):
|
||||
self.stdout.write(f"SKIP {code}: no body streamfield")
|
||||
return
|
||||
|
||||
body = specific.body
|
||||
raw_data = list(body.raw_data)
|
||||
no_cc = NO_CC_TEXT.get(code) or NO_CC_TEXT["en"]
|
||||
contact_url = _localized_url(131, locale) # contact
|
||||
services_url = _localized_url(129, locale) # services
|
||||
changed = False
|
||||
|
||||
for block in raw_data:
|
||||
if block.get("type") != "saas_cta_footer":
|
||||
continue
|
||||
value = block.get("value")
|
||||
if not isinstance(value, dict):
|
||||
continue
|
||||
if _fix_cta_footer(
|
||||
value,
|
||||
no_cc_text=no_cc,
|
||||
primary_url=contact_url,
|
||||
secondary_url=services_url,
|
||||
):
|
||||
block["value"] = value
|
||||
changed = True
|
||||
|
||||
if not changed:
|
||||
self.stdout.write(f"OK {code}: no cta footer changes needed")
|
||||
return
|
||||
|
||||
self.stdout.write(
|
||||
f"CHG {code}: fixed saas_cta_footer no_credit_card_text/urls"
|
||||
)
|
||||
specific.body = StreamValue(body.stream_block, raw_data, is_lazy=True)
|
||||
if apply_changes:
|
||||
rev = specific.save_revision()
|
||||
rev.publish()
|
||||
|
||||
Reference in New Issue
Block a user