Compare commits
14 Commits
4a24a125f5
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| df28667a9c | |||
| 210f90b899 | |||
| e04b5dd8b4 | |||
| 0d18d3b526 | |||
| 0910ff850a | |||
| 9c8d6a8ecf | |||
| 37650b3325 | |||
| 72de8844bb | |||
| 556faacc78 | |||
| 856f7333d4 | |||
| 0919739688 | |||
| d8e1542e82 | |||
| f89951aac4 | |||
| 53fbc7fb38 |
61
Jenkinsfile
vendored
61
Jenkinsfile
vendored
@@ -165,6 +165,67 @@ PY
|
|||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stage('Fix Capabilities FAQ') {
|
||||||
|
agent { label 'built-in' }
|
||||||
|
options {
|
||||||
|
timeout(time: 5, unit: 'MINUTES')
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -e
|
||||||
|
REMOTE_CMD="cd '${STAGING_AUDIT_PROJECT_DIR}' && '${STAGING_AUDIT_MANAGE}' fix_capabilities_faq --apply"
|
||||||
|
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"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Fix No Credit Card Copy') {
|
||||||
|
agent { label 'built-in' }
|
||||||
|
options {
|
||||||
|
timeout(time: 5, unit: 'MINUTES')
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -e
|
||||||
|
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"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Recompress Staging Assets') {
|
||||||
|
agent { label 'built-in' }
|
||||||
|
options {
|
||||||
|
timeout(time: 10, unit: 'MINUTES')
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -e
|
||||||
|
REMOTE_CMD="cd '${STAGING_AUDIT_PROJECT_DIR}' && '${STAGING_AUDIT_MANAGE}' compress --force"
|
||||||
|
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"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Wait For Staging Health') {
|
||||||
|
agent { label 'built-in' }
|
||||||
|
options {
|
||||||
|
timeout(time: 5, unit: 'MINUTES')
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -e
|
||||||
|
for i in $(seq 1 30); do
|
||||||
|
code_nl=$(curl -sS -o /dev/null -w "%{http_code}" https://mandelstudio.welkombij.mandelblog.com/ || true)
|
||||||
|
code_en=$(curl -sS -o /dev/null -w "%{http_code}" https://mandelstudio.welkombij.mandelblog.com/en/ || true)
|
||||||
|
echo "healthcheck attempt=$i nl=$code_nl en=$code_en"
|
||||||
|
if [ "$code_nl" = "200" ] && [ "$code_en" = "200" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
echo "staging did not become healthy in time"
|
||||||
|
exit 1
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
stage('Post-Deploy Multilingual Audit') {
|
stage('Post-Deploy Multilingual Audit') {
|
||||||
agent { label 'built-in' }
|
agent { label 'built-in' }
|
||||||
options {
|
options {
|
||||||
|
|||||||
134
mandelstudio/management/commands/fix_capabilities_faq.py
Normal file
134
mandelstudio/management/commands/fix_capabilities_faq.py
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
|
from wagtail.blocks import StreamValue
|
||||||
|
from wagtail.models import Locale, Page
|
||||||
|
|
||||||
|
from mandelstudio.management.commands._agency_content import COMMON_CTA, HOME_COPY
|
||||||
|
|
||||||
|
|
||||||
|
def _make_faq_items(locale_code: str) -> list[dict[str, Any]]:
|
||||||
|
cfg = HOME_COPY.get(locale_code) or {}
|
||||||
|
faqs = cfg.get("faqs") or []
|
||||||
|
items: list[dict[str, Any]] = []
|
||||||
|
for question, answer, category in faqs:
|
||||||
|
items.append(
|
||||||
|
{
|
||||||
|
"type": "item",
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"value": {
|
||||||
|
"question": question,
|
||||||
|
"answer": answer,
|
||||||
|
"category": category,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return items
|
||||||
|
|
||||||
|
|
||||||
|
def _update_saas_faq_block(value: dict[str, Any], *, locale_code: str) -> bool:
|
||||||
|
"""Update a `saas_faq` block in-place. Returns True if changed."""
|
||||||
|
desired_items = _make_faq_items(locale_code)
|
||||||
|
if not desired_items:
|
||||||
|
return False
|
||||||
|
|
||||||
|
changed = False
|
||||||
|
if value.get("faqs") != desired_items:
|
||||||
|
value["faqs"] = desired_items
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
# Keep the existing CTA URL (it is page-specific and already localized),
|
||||||
|
# but ensure the CTA label is consistent for the locale.
|
||||||
|
if "contact_cta_text" in value and locale_code in COMMON_CTA:
|
||||||
|
desired_cta = COMMON_CTA[locale_code]["primary"]
|
||||||
|
if value.get("contact_cta_text") != desired_cta:
|
||||||
|
value["contact_cta_text"] = desired_cta
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
return changed
|
||||||
|
|
||||||
|
|
||||||
|
def _update_page_body(page: Page, *, locale_code: str) -> bool:
|
||||||
|
specific = page.specific
|
||||||
|
if not hasattr(specific, "body"):
|
||||||
|
return False
|
||||||
|
|
||||||
|
body = specific.body
|
||||||
|
raw_data = list(body.raw_data)
|
||||||
|
changed = False
|
||||||
|
for block in raw_data:
|
||||||
|
if block.get("type") != "saas_faq":
|
||||||
|
continue
|
||||||
|
value = block.get("value")
|
||||||
|
if isinstance(value, dict):
|
||||||
|
if _update_saas_faq_block(value, locale_code=locale_code):
|
||||||
|
block["value"] = value
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
if not changed:
|
||||||
|
return False
|
||||||
|
|
||||||
|
specific.body = StreamValue(body.stream_block, raw_data, is_lazy=True)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Fix the Capabilities (mogelijkheden) page FAQ items across locales"
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument(
|
||||||
|
"--apply",
|
||||||
|
action="store_true",
|
||||||
|
help="Persist and publish changes (default is dry-run).",
|
||||||
|
)
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
apply_changes = options["apply"]
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
target_locales = list(Locale.objects.all().order_by("language_code"))
|
||||||
|
|
||||||
|
with transaction.atomic():
|
||||||
|
for locale in target_locales:
|
||||||
|
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
|
||||||
|
|
||||||
|
changed = _update_page_body(page, locale_code=code)
|
||||||
|
if not changed:
|
||||||
|
self.stdout.write(f"OK {code}: no FAQ changes needed")
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.stdout.write(f"CHG {code}: updated saas_faq items")
|
||||||
|
if apply_changes:
|
||||||
|
rev = page.save_revision()
|
||||||
|
rev.publish()
|
||||||
|
|
||||||
|
if not apply_changes:
|
||||||
|
raise CommandError(
|
||||||
|
"Dry-run complete. Re-run with --apply to persist changes."
|
||||||
|
)
|
||||||
181
mandelstudio/management/commands/fix_no_credit_card_text.py
Normal file
181
mandelstudio/management/commands/fix_no_credit_card_text.py
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
from urllib.parse import unquote
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
|
from wagtail.blocks import StreamValue
|
||||||
|
from wagtail.models import Locale, Page
|
||||||
|
|
||||||
|
NO_CC_TEXT = {
|
||||||
|
"nl": "No credit card required",
|
||||||
|
"en": "No credit card required",
|
||||||
|
"de": "Keine Kreditkarte erforderlich",
|
||||||
|
"fr": "Aucune carte bancaire requise",
|
||||||
|
"es": "No se requiere tarjeta",
|
||||||
|
"it": "Nessuna carta richiesta",
|
||||||
|
"pt": "Não é necessário cartão",
|
||||||
|
"ru": "Карта не требуется",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _localized_url(source_id: int, locale: Locale) -> str | None:
|
||||||
|
source = Page.objects.get(id=source_id)
|
||||||
|
translated = (
|
||||||
|
Page.objects.filter(translation_key=source.translation_key, locale=locale)
|
||||||
|
.specific()
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
chosen = translated or source
|
||||||
|
return getattr(chosen, "url", None)
|
||||||
|
|
||||||
|
|
||||||
|
def _fix_cta_footer(
|
||||||
|
value: dict[str, Any],
|
||||||
|
*,
|
||||||
|
no_cc_text: str,
|
||||||
|
primary_url: str | None,
|
||||||
|
secondary_url: str | None,
|
||||||
|
) -> bool:
|
||||||
|
changed = False
|
||||||
|
|
||||||
|
raw = value.get("no_credit_card_text")
|
||||||
|
if isinstance(raw, str):
|
||||||
|
cleaned = raw.replace(""", '"').strip()
|
||||||
|
# Remove any accidental "language detector" message fragments.
|
||||||
|
if "is not Dutch" in cleaned or "translation from" in cleaned:
|
||||||
|
cleaned = no_cc_text
|
||||||
|
if cleaned != no_cc_text:
|
||||||
|
value["no_credit_card_text"] = no_cc_text
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
value["no_credit_card_text"] = no_cc_text
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
# Ensure CTA URLs are readable and not percent-encoded.
|
||||||
|
for key in ("primary_cta_url", "secondary_cta_url"):
|
||||||
|
url = value.get(key)
|
||||||
|
if isinstance(url, str) and "%" in url:
|
||||||
|
decoded = unquote(url)
|
||||||
|
if decoded != url:
|
||||||
|
value[key] = decoded
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
# Align CTA URLs to the translated contact/services pages when available.
|
||||||
|
if primary_url and value.get("primary_cta_url") != primary_url:
|
||||||
|
value["primary_cta_url"] = primary_url
|
||||||
|
changed = True
|
||||||
|
if secondary_url and value.get("secondary_cta_url") != secondary_url:
|
||||||
|
value["secondary_cta_url"] = secondary_url
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
return changed
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = (
|
||||||
|
"Fix corrupted 'no credit card' copy in saas_cta_footer blocks across locales"
|
||||||
|
)
|
||||||
|
|
||||||
|
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",
|
||||||
|
help="Persist and publish changes (default is dry-run).",
|
||||||
|
)
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
apply_changes = options["apply"]
|
||||||
|
page_id = options.get("page_id")
|
||||||
|
|
||||||
|
with transaction.atomic():
|
||||||
|
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 source is None:
|
||||||
|
raise CommandError(
|
||||||
|
"Could not find source page nl/slug=mogelijkheden"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
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()
|
||||||
25
mandelstudio/middleware.py
Normal file
25
mandelstudio/middleware.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from django.http import HttpRequest, HttpResponsePermanentRedirect
|
||||||
|
|
||||||
|
|
||||||
|
class RedirectApexToWwwMiddleware:
|
||||||
|
"""Redirect `mandelblog.com` to `www.mandelblog.com` for production.
|
||||||
|
|
||||||
|
We keep this project-scoped and host-specific so staging hostnames and other
|
||||||
|
Mandel environments are unaffected.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, get_response):
|
||||||
|
self.get_response = get_response
|
||||||
|
|
||||||
|
def __call__(self, request: HttpRequest):
|
||||||
|
# Use the raw Host header so proxy-specific X-Forwarded-Host rewrites
|
||||||
|
# can't prevent the apex redirect.
|
||||||
|
host = (request.META.get("HTTP_HOST") or "").split(":")[0].lower()
|
||||||
|
if host == "mandelblog.com":
|
||||||
|
destination = request.build_absolute_uri().replace(
|
||||||
|
"://mandelblog.com", "://www.mandelblog.com", 1
|
||||||
|
)
|
||||||
|
return HttpResponsePermanentRedirect(destination)
|
||||||
|
return self.get_response(request)
|
||||||
@@ -116,6 +116,10 @@ if "django.middleware.locale.LocaleMiddleware" not in MIDDLEWARE:
|
|||||||
else:
|
else:
|
||||||
MIDDLEWARE.insert(0, "django.middleware.locale.LocaleMiddleware")
|
MIDDLEWARE.insert(0, "django.middleware.locale.LocaleMiddleware")
|
||||||
|
|
||||||
|
# Redirect production apex to `www` for a single canonical domain.
|
||||||
|
if "mandelstudio.middleware.RedirectApexToWwwMiddleware" not in MIDDLEWARE:
|
||||||
|
MIDDLEWARE.insert(0, "mandelstudio.middleware.RedirectApexToWwwMiddleware")
|
||||||
|
|
||||||
LANGUAGE_CODE = "nl"
|
LANGUAGE_CODE = "nl"
|
||||||
LANGUAGES = [
|
LANGUAGES = [
|
||||||
("nl", "Nederlands"),
|
("nl", "Nederlands"),
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
{% load i18n ocyan_thumbnail %}
|
{% load i18n ocyan_thumbnail mandelstudio_i18n %}
|
||||||
{% if menu_items %}
|
{% if menu_items %}
|
||||||
{% for menu_item in menu_items %}
|
{% for menu_item in menu_items %}
|
||||||
{% with category_icon=menu_item.category.icons.first %}
|
{% with category_icon=menu_item.category.icons.first %}
|
||||||
|
{% with category_url=menu_item.get_absolute_url|language_neutral_path %}
|
||||||
{% if menu_item.has_children %}
|
{% if menu_item.has_children %}
|
||||||
<li class="nav-item has_children">
|
<li class="nav-item has_children">
|
||||||
<a class="nav-link category-label" data-name="{{ menu_item.name|safe }}" data-href="{{ menu_item.get_absolute_url }}" tabindex="-1">
|
<a class="nav-link category-label" data-name="{{ menu_item.name|safe }}" data-href="{{ category_url }}" tabindex="-1">
|
||||||
<span>{% trans "Show everything in" %}</span>{{ menu_item.name }}
|
<span>{% trans "Show everything in" %}</span>{{ menu_item.name }}
|
||||||
</a>
|
</a>
|
||||||
<ul class="menu-level">
|
<ul class="menu-level">
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="nav-item child">
|
<li class="nav-item child">
|
||||||
<a class="nav-link child-category" href="{{ menu_item.get_absolute_url }}" tabindex="-1">
|
<a class="nav-link child-category" href="{{ category_url }}" tabindex="-1">
|
||||||
{{ menu_item.name }}
|
{{ menu_item.name }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@@ -20,5 +21,6 @@
|
|||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
{% endwith %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -19,6 +19,31 @@ def locale_rows(payload: dict) -> list[tuple[str, dict]]:
|
|||||||
summary = payload.get("summary", {})
|
summary = payload.get("summary", {})
|
||||||
return [(locale, data) for locale, data in summary.items() if locale != "snippets"]
|
return [(locale, data) for locale, data in summary.items() if locale != "snippets"]
|
||||||
|
|
||||||
|
def enabled_locales() -> set[str] | None:
|
||||||
|
"""Return the locales this project actually enables, or None if unknown.
|
||||||
|
|
||||||
|
Jenkins runs this repo for the `mandelstudio` staging site. We only want CI to
|
||||||
|
block on locales that are enabled for this project, otherwise a broken
|
||||||
|
translation (or an intentionally disabled locale) can keep the pipeline red.
|
||||||
|
"""
|
||||||
|
|
||||||
|
config_path = PROJECT_ROOT / "mandelstudio" / "ocyan.json"
|
||||||
|
if not config_path.exists():
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
payload = load_json(config_path)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
languages = (
|
||||||
|
(payload.get("settings") or {})
|
||||||
|
.get("i18n", {})
|
||||||
|
.get("languages")
|
||||||
|
)
|
||||||
|
if not isinstance(languages, list):
|
||||||
|
return None
|
||||||
|
return {str(code) for code in languages if code}
|
||||||
|
|
||||||
|
|
||||||
def print_error(payload: dict) -> int:
|
def print_error(payload: dict) -> int:
|
||||||
error = payload.get("error")
|
error = payload.get("error")
|
||||||
@@ -28,7 +53,7 @@ def print_error(payload: dict) -> int:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def print_summary(payload: dict) -> tuple[int, int]:
|
def print_summary(payload: dict, *, enabled: set[str] | None) -> tuple[int, int]:
|
||||||
total_block = 0
|
total_block = 0
|
||||||
total_warn = 0
|
total_warn = 0
|
||||||
for locale, data in locale_rows(payload):
|
for locale, data in locale_rows(payload):
|
||||||
@@ -36,12 +61,15 @@ def print_summary(payload: dict) -> tuple[int, int]:
|
|||||||
block = int(sev.get("block", 0) or 0)
|
block = int(sev.get("block", 0) or 0)
|
||||||
warn = int(sev.get("warn", 0) or 0)
|
warn = int(sev.get("warn", 0) or 0)
|
||||||
log = int(sev.get("log", 0) or 0)
|
log = int(sev.get("log", 0) or 0)
|
||||||
|
included = enabled is None or locale in enabled
|
||||||
|
if included:
|
||||||
total_block += block
|
total_block += block
|
||||||
total_warn += warn
|
total_warn += warn
|
||||||
|
suffix = "" if included else " (ignored)"
|
||||||
print(
|
print(
|
||||||
f"LOCALE {locale}: issues_found={data.get('issues_found', 0)} "
|
f"LOCALE {locale}: issues_found={data.get('issues_found', 0)} "
|
||||||
f"issues_remaining={data.get('remaining_issues', 0)} "
|
f"issues_remaining={data.get('remaining_issues', 0)} "
|
||||||
f"block={block} warn={warn} log={log}"
|
f"block={block} warn={warn} log={log}{suffix}"
|
||||||
)
|
)
|
||||||
return total_block, total_warn
|
return total_block, total_warn
|
||||||
|
|
||||||
@@ -51,12 +79,14 @@ def _cta_issue_is_allowed_now(locale: str, issue: dict) -> bool:
|
|||||||
return issue.get("severity") == "block" and issue.get("issue_type") == "cta_language_mismatch"
|
return issue.get("severity") == "block" and issue.get("issue_type") == "cta_language_mismatch"
|
||||||
|
|
||||||
|
|
||||||
def effective_block_count(payload: dict) -> tuple[int, int]:
|
def effective_block_count(payload: dict, *, enabled: set[str] | None) -> tuple[int, int]:
|
||||||
"""Return (effective_block, ignored_block) after applying allowlists."""
|
"""Return (effective_block, ignored_block) after applying allowlists."""
|
||||||
ignored = 0
|
ignored = 0
|
||||||
block = 0
|
block = 0
|
||||||
issues = payload.get("issues") or {}
|
issues = payload.get("issues") or {}
|
||||||
for locale, data in locale_rows(payload):
|
for locale, data in locale_rows(payload):
|
||||||
|
if enabled is not None and locale not in enabled:
|
||||||
|
continue
|
||||||
locale_issues = issues.get(locale) or []
|
locale_issues = issues.get(locale) or []
|
||||||
for issue in locale_issues:
|
for issue in locale_issues:
|
||||||
if issue.get("severity") != "block":
|
if issue.get("severity") != "block":
|
||||||
@@ -103,11 +133,12 @@ def main() -> int:
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
current = load_json(Path(args.json))
|
current = load_json(Path(args.json))
|
||||||
|
enabled = enabled_locales()
|
||||||
error_status = print_error(current)
|
error_status = print_error(current)
|
||||||
if error_status:
|
if error_status:
|
||||||
return error_status
|
return error_status
|
||||||
total_block, total_warn = print_summary(current)
|
total_block, total_warn = print_summary(current, enabled=enabled)
|
||||||
effective_block, ignored_block = effective_block_count(current)
|
effective_block, ignored_block = effective_block_count(current, enabled=enabled)
|
||||||
if ignored_block:
|
if ignored_block:
|
||||||
print(f"IGNORED: {ignored_block} block issue(s) now allowed by current rules")
|
print(f"IGNORED: {ignored_block} block issue(s) now allowed by current rules")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user