Compare commits
26 Commits
5359a0a5e2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| df28667a9c | |||
| 210f90b899 | |||
| e04b5dd8b4 | |||
| 0d18d3b526 | |||
| 0910ff850a | |||
| 9c8d6a8ecf | |||
| 37650b3325 | |||
| 72de8844bb | |||
| 556faacc78 | |||
| 856f7333d4 | |||
| 0919739688 | |||
| d8e1542e82 | |||
| f89951aac4 | |||
| 53fbc7fb38 | |||
| 4a24a125f5 | |||
| 165bf47291 | |||
| f109e60b03 | |||
| 8066793131 | |||
| 7a3c649fb4 | |||
| 3eac7ca0b6 | |||
| 9624eec735 | |||
| 891639c7fc | |||
| be7831b42e | |||
| 80ab2afdbb | |||
| 3e0c9c14a2 | |||
| d2f62ff549 |
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') {
|
||||
agent { label 'built-in' }
|
||||
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:
|
||||
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"
|
||||
LANGUAGES = [
|
||||
("nl", "Nederlands"),
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
/* Scoped mobile header fixes for MandelBlog Studio.
|
||||
Keep changes local to the Carbasa mega header to avoid desktop regressions. */
|
||||
|
||||
@media (max-width: 991.98px) {
|
||||
header.mega_header .header-inner .container {
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
padding-top: 0.5rem;
|
||||
padding-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner .navbar-brand {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
position: relative;
|
||||
z-index: 30;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner .navbar-brand .logo.big_brand img,
|
||||
header.mega_header .header-inner .navbar-brand .logo img {
|
||||
max-height: 36px;
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner .header-right {
|
||||
padding-left: 0;
|
||||
margin-left: auto;
|
||||
gap: 0.5rem;
|
||||
position: relative;
|
||||
z-index: 30;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner .header-right .user-button {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner .navbar-toggler {
|
||||
position: static;
|
||||
inset: auto;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
margin: 0 0 0 0.5rem;
|
||||
box-shadow: none;
|
||||
background: #fff;
|
||||
border: 1px solid rgba(15, 23, 42, 0.12);
|
||||
z-index: 35;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner #navbarSupportedContent.show {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
overflow: auto;
|
||||
background: #fff;
|
||||
padding: 5.25rem 1.25rem 6rem;
|
||||
z-index: 40;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner #navbarSupportedContent.show ~ .header-right {
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner #navbarSupportedContent .brand-wrapper {
|
||||
display: none;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner #navbarSupportedContent .navbar-nav {
|
||||
width: 100%;
|
||||
align-items: stretch;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner #navbarSupportedContent .navbar-nav > li {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner #navbarSupportedContent .navbar-nav > li > a.nav-link,
|
||||
header.mega_header .header-inner #navbarSupportedContent .navbar-nav > li > a.toggler.nav-link {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0.85rem 0.25rem;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner #navbarSupportedContent .dropdown-menu {
|
||||
position: static;
|
||||
float: none;
|
||||
width: 100%;
|
||||
border: 0;
|
||||
padding: 0.25rem 0 0.75rem;
|
||||
margin: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
header.mega_header .header-inner #navbarSupportedContent .dropdown-menu .nav-link {
|
||||
justify-content: flex-start;
|
||||
padding: 0.6rem 0.25rem;
|
||||
font-size: 1rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
{{ block.super }}
|
||||
{# Ensure Carbasa webshop styling is present so responsive header/footer render correctly. #}
|
||||
<link rel="stylesheet" type="text/x-scss" href="{% static 'carbasa/webshop_base.scss' %}">
|
||||
{# Project-scoped header mobile fixes (plain CSS to avoid SCSS compilation at runtime). #}
|
||||
<link rel="stylesheet" href="{% static 'mandelstudio/header_mobile.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block extrahead %}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
{% load i18n ocyan_thumbnail %}
|
||||
{% load i18n ocyan_thumbnail mandelstudio_i18n %}
|
||||
{% if menu_items %}
|
||||
{% for menu_item in menu_items %}
|
||||
{% with category_icon=menu_item.category.icons.first %}
|
||||
{% with category_url=menu_item.get_absolute_url|language_neutral_path %}
|
||||
{% if menu_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 }}
|
||||
</a>
|
||||
<ul class="menu-level">
|
||||
{% else %}
|
||||
<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 }}
|
||||
</a>
|
||||
</li>
|
||||
@@ -20,5 +21,6 @@
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
@@ -19,6 +19,31 @@ def locale_rows(payload: dict) -> list[tuple[str, dict]]:
|
||||
summary = payload.get("summary", {})
|
||||
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:
|
||||
error = payload.get("error")
|
||||
@@ -28,7 +53,7 @@ def print_error(payload: dict) -> int:
|
||||
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_warn = 0
|
||||
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)
|
||||
warn = int(sev.get("warn", 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_warn += warn
|
||||
suffix = "" if included else " (ignored)"
|
||||
print(
|
||||
f"LOCALE {locale}: issues_found={data.get('issues_found', 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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
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."""
|
||||
ignored = 0
|
||||
block = 0
|
||||
issues = payload.get("issues") or {}
|
||||
for locale, data in locale_rows(payload):
|
||||
if enabled is not None and locale not in enabled:
|
||||
continue
|
||||
locale_issues = issues.get(locale) or []
|
||||
for issue in locale_issues:
|
||||
if issue.get("severity") != "block":
|
||||
@@ -103,11 +133,12 @@ def main() -> int:
|
||||
args = parser.parse_args()
|
||||
|
||||
current = load_json(Path(args.json))
|
||||
enabled = enabled_locales()
|
||||
error_status = print_error(current)
|
||||
if error_status:
|
||||
return error_status
|
||||
total_block, total_warn = print_summary(current)
|
||||
effective_block, ignored_block = effective_block_count(current)
|
||||
total_block, total_warn = print_summary(current, enabled=enabled)
|
||||
effective_block, ignored_block = effective_block_count(current, enabled=enabled)
|
||||
if ignored_block:
|
||||
print(f"IGNORED: {ignored_block} block issue(s) now allowed by current rules")
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ trap 'rm -f "$TMP_FILE" "$TMP_DEBUG"' EXIT
|
||||
|
||||
REMOTE_DEBUG_CMD="cd '${STAGING_AUDIT_PROJECT_DIR}' && '${STAGING_AUDIT_MANAGE}' shell -c \"\
|
||||
from django.template.loader import get_template; \
|
||||
from django.template import Context; \
|
||||
import pathlib; \
|
||||
import os; \
|
||||
import mandelstudio; \
|
||||
@@ -31,13 +30,6 @@ t1=get_template('carbasa/headers/header.html'); \
|
||||
t2=get_template('engine/pages/base_home_page.html'); \
|
||||
print('carbasa/headers/header.html -> ' + getattr(getattr(t1,'origin',None),'name','(no origin)')); \
|
||||
print('engine/pages/base_home_page.html -> ' + getattr(getattr(t2,'origin',None),'name','(no origin)')); \
|
||||
try: \
|
||||
t3=get_template('layout.html'); \
|
||||
t3.render(Context({'request': None})); \
|
||||
print('render_layout_ok=True'); \
|
||||
except Exception as exc: \
|
||||
print('render_layout_ok=False'); \
|
||||
print('render_layout_error=' + repr(exc)); \
|
||||
\""
|
||||
|
||||
REMOTE_CMD="cd '${STAGING_AUDIT_PROJECT_DIR}' && '${STAGING_AUDIT_MANAGE}' audit_locales --format=json"
|
||||
|
||||
Reference in New Issue
Block a user