From 737a3e377c46e578593ffad8247c690eaf360c20 Mon Sep 17 00:00:00 2001 From: Evarin Date: Sun, 30 Aug 2020 11:58:01 +0200 Subject: [PATCH] =?UTF-8?q?Sitecof=20:=20Surcharge=20get=5Furl=5Fparts=20p?= =?UTF-8?q?lut=C3=B4t=20que=20get=5Furl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cof/settings/cof_prod.py | 4 ++-- gestioncof/cms/models.py | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cof/settings/cof_prod.py b/cof/settings/cof_prod.py index b2f1b4ff..5fa9e6b0 100644 --- a/cof/settings/cof_prod.py +++ b/cof/settings/cof_prod.py @@ -206,5 +206,5 @@ MAIL_DATA = { # SiteCOF URL rewrite rules # --- -SITECOF_INTERNAL_URL = r"/gestion/(en/|fr/|)sitecof/" -SITECOF_PUBLIC_URL = r"/\\1news/" +SITECOF_INTERNAL_URL = r"^/gestion/(en/|fr/|)sitecof/" +SITECOF_PUBLIC_URL = "/\\1news/" diff --git a/gestioncof/cms/models.py b/gestioncof/cms/models.py index 0178218e..88650e5f 100644 --- a/gestioncof/cms/models.py +++ b/gestioncof/cms/models.py @@ -14,16 +14,19 @@ from wagtail.images.edit_handlers import ImageChooserPanel # Récriture des URL publiques par surcharge de get_url class COFRewriteUrlMixin: - def get_url(self, request=None, current_site=None): - url = super().get_url(request, current_site) - pattern = getattr( - settings, "SITECOF_INTERNAL_URL", r"/gestion/(en/|fr/|)sitecof/" - ) - replace = getattr(settings, "SITECOF_PUBLIC_URL", "/\\1news/") - url = re.sub(pattern, replace, url) - return url + def get_url_parts(self, request=None, current_site=None): + (site_id, root_url, page_path) = super().get_url_parts(request) - url = property(get_url) + if page_path is None: + return (site_id, root_url, page_path) + + pattern = getattr(settings, "SITECOF_INTERNAL_URL", r"^/(en/|fr/|)sitecof/") + replace = getattr(settings, "SITECOF_PUBLIC_URL", "/\\1news/") + + print(pattern, replace, page_path) + page_path = re.sub(pattern, replace, page_path) + + return (site_id, root_url, page_path) # Page pouvant afficher des actualités