From a59711183d7d86320c7d5967e7dceca0baf3065f Mon Sep 17 00:00:00 2001 From: Evarin Date: Sun, 30 Aug 2020 11:31:44 +0200 Subject: [PATCH 1/3] Sitecof: Rewrite public URLs --- cof/settings/cof_prod.py | 7 +++++++ gestioncof/cms/models.py | 29 +++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/cof/settings/cof_prod.py b/cof/settings/cof_prod.py index 0f73841e..b2f1b4ff 100644 --- a/cof/settings/cof_prod.py +++ b/cof/settings/cof_prod.py @@ -201,3 +201,10 @@ MAIL_DATA = { "REPLYTO": "BdA-Revente ", }, } + +# --- +# SiteCOF URL rewrite rules +# --- + +SITECOF_INTERNAL_URL = r"/gestion/(en/|fr/|)sitecof/" +SITECOF_PUBLIC_URL = r"/\\1news/" diff --git a/gestioncof/cms/models.py b/gestioncof/cms/models.py index 1e1aad43..0178218e 100644 --- a/gestioncof/cms/models.py +++ b/gestioncof/cms/models.py @@ -1,3 +1,6 @@ +import re + +from django.conf import settings from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.db import models from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel @@ -9,6 +12,20 @@ from wagtail.images.blocks import ImageChooserBlock 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 + + url = property(get_url) + + # Page pouvant afficher des actualités class COFActuIndexMixin: @property @@ -18,7 +35,7 @@ class COFActuIndexMixin: # Racine du site du COF -class COFRootPage(RoutablePageMixin, Page, COFActuIndexMixin): +class COFRootPage(COFRewriteUrlMixin, RoutablePageMixin, Page, COFActuIndexMixin): introduction = RichTextField("Introduction") content_panels = Page.content_panels + [ @@ -62,7 +79,7 @@ class IFrameBlock(blocks.StructBlock): # Page lambda du site -class COFPage(Page): +class COFPage(COFRewriteUrlMixin, Page): body = StreamField( [ ("heading", blocks.CharBlock(classname="full title")), @@ -83,7 +100,7 @@ class COFPage(Page): # Actualités -class COFActuIndexPage(Page, COFActuIndexMixin): +class COFActuIndexPage(COFRewriteUrlMixin, Page, COFActuIndexMixin): subpage_types = ["COFActuPage"] parent_page_types = ["COFRootPage"] @@ -108,7 +125,7 @@ class COFActuIndexPage(Page, COFActuIndexMixin): return context -class COFActuPage(RoutablePageMixin, Page): +class COFActuPage(COFRewriteUrlMixin, RoutablePageMixin, Page): chapo = models.TextField("Description rapide", blank=True) body = RichTextField("Contenu") image = models.ForeignKey( @@ -145,7 +162,7 @@ class COFActuPage(RoutablePageMixin, Page): # Annuaires (Clubs, partenaires, bonnes adresses) -class COFDirectoryPage(Page): +class COFDirectoryPage(COFRewriteUrlMixin, Page): introduction = RichTextField("Introduction") alphabetique = models.BooleanField( "Tri par ordre alphabétique ?", default=True, blank=True @@ -171,7 +188,7 @@ class COFDirectoryPage(Page): verbose_name_plural = "Annuaires" -class COFDirectoryEntryPage(Page): +class COFDirectoryEntryPage(COFRewriteUrlMixin, Page): body = RichTextField("Description") links = StreamField( [ -- 2.46.1 From 737a3e377c46e578593ffad8247c690eaf360c20 Mon Sep 17 00:00:00 2001 From: Evarin Date: Sun, 30 Aug 2020 11:58:01 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Sitecof=20:=20Surcharge=20get=5Furl=5Fparts?= =?UTF-8?q?=20plut=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 -- 2.46.1 From d1f5cb684054c980d6c55c4da3e513a7d6f3b8c3 Mon Sep 17 00:00:00 2001 From: Robin Champenois Date: Sun, 30 Aug 2020 12:48:47 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Print=20oubli=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestioncof/cms/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gestioncof/cms/models.py b/gestioncof/cms/models.py index 88650e5f..b5dab78b 100644 --- a/gestioncof/cms/models.py +++ b/gestioncof/cms/models.py @@ -23,7 +23,6 @@ class COFRewriteUrlMixin: 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) -- 2.46.1