fix: repair RU capabilities CTA note
This commit is contained in:
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@@ -186,7 +186,7 @@ PY
|
|||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
set -e
|
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"
|
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):
|
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(
|
parser.add_argument(
|
||||||
"--apply",
|
"--apply",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
@@ -88,73 +93,89 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
apply_changes = options["apply"]
|
apply_changes = options["apply"]
|
||||||
|
page_id = options.get("page_id")
|
||||||
# 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")
|
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for locale in Locale.objects.all().order_by("language_code"):
|
if page_id:
|
||||||
code = locale.language_code
|
page = Page.objects.filter(id=page_id).specific().first()
|
||||||
page = (
|
if page is None:
|
||||||
Page.objects.filter(
|
raise CommandError(f"Page id={page_id} not found")
|
||||||
translation_key=source.translation_key, locale=locale
|
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()
|
.specific()
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
if page is None:
|
if source is None:
|
||||||
self.stdout.write(f"SKIP {code}: no translation for mogelijkheden")
|
raise CommandError(
|
||||||
continue
|
"Could not find source page nl/slug=mogelijkheden"
|
||||||
|
)
|
||||||
|
|
||||||
specific = page.specific
|
for locale in Locale.objects.all().order_by("language_code"):
|
||||||
if not hasattr(specific, "body"):
|
code = locale.language_code
|
||||||
self.stdout.write(f"SKIP {code}: no body streamfield")
|
page = (
|
||||||
continue
|
Page.objects.filter(
|
||||||
|
translation_key=source.translation_key, locale=locale
|
||||||
body = specific.body
|
)
|
||||||
raw_data = list(body.raw_data)
|
.specific()
|
||||||
no_cc = NO_CC_TEXT.get(code) or NO_CC_TEXT["en"]
|
.first()
|
||||||
contact_url = _localized_url(131, locale) # contact
|
)
|
||||||
services_url = _localized_url(129, locale) # services
|
if page is None:
|
||||||
changed = False
|
self.stdout.write(
|
||||||
for block in raw_data:
|
f"SKIP {code}: no translation for mogelijkheden"
|
||||||
if block.get("type") != "saas_cta_footer":
|
)
|
||||||
continue
|
continue
|
||||||
value = block.get("value")
|
self._fix_page(page, apply_changes=apply_changes)
|
||||||
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()
|
|
||||||
|
|
||||||
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 _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