From e56123e5f71b1a026956f2c083ce80cff05a87dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 30 Aug 2020 11:31:44 +0200 Subject: [PATCH] Sitecof: always use absolute URLs Remaining to do: change the 'sitecof' slug to 'news' in production. By using absolute URLs we can prevent Daphne from adding the /gestion prefix and serve the COF site under cof.ens.fr/news rather than cof.ens.fr/gestion/sitecof --- gestioncof/cms/models.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/gestioncof/cms/models.py b/gestioncof/cms/models.py index 57881084..d88e0208 100644 --- a/gestioncof/cms/models.py +++ b/gestioncof/cms/models.py @@ -9,6 +9,12 @@ from wagtail.images.blocks import ImageChooserBlock from wagtail.images.edit_handlers import ImageChooserPanel +# Récriture des URL publiques par surcharge de get_url +class AbsoluteURLMixin: + def get_url(self, request=None, current_site=None): + return self.get_full_url(request=request) + + # Page pouvant afficher des actualités class COFActuIndexMixin: @property @@ -18,7 +24,7 @@ class COFActuIndexMixin: # Racine du site du COF -class COFRootPage(RoutablePageMixin, Page, COFActuIndexMixin): +class COFRootPage(AbsoluteURLMixin, RoutablePageMixin, Page, COFActuIndexMixin): introduction = RichTextField("Introduction") content_panels = Page.content_panels + [ @@ -62,7 +68,7 @@ class IFrameBlock(blocks.StructBlock): # Page lambda du site -class COFPage(Page): +class COFPage(AbsoluteURLMixin, Page): body = StreamField( [ ("heading", blocks.CharBlock(classname="full title")), @@ -83,7 +89,7 @@ class COFPage(Page): # Actualités -class COFActuIndexPage(Page, COFActuIndexMixin): +class COFActuIndexPage(AbsoluteURLMixin, Page, COFActuIndexMixin): subpage_types = ["COFActuPage"] parent_page_types = ["COFRootPage"] @@ -108,7 +114,7 @@ class COFActuIndexPage(Page, COFActuIndexMixin): return context -class COFActuPage(RoutablePageMixin, Page): +class COFActuPage(AbsoluteURLMixin, RoutablePageMixin, Page): chapo = models.TextField("Description rapide", blank=True) body = RichTextField("Contenu") image = models.ForeignKey( @@ -145,7 +151,7 @@ class COFActuPage(RoutablePageMixin, Page): # Annuaires (Clubs, partenaires, bonnes adresses) -class COFDirectoryPage(Page): +class COFDirectoryPage(AbsoluteURLMixin, Page): introduction = RichTextField("Introduction") alphabetique = models.BooleanField( "Tri par ordre alphabétique ?", default=True, blank=True @@ -171,7 +177,7 @@ class COFDirectoryPage(Page): verbose_name_plural = "Annuaires" -class COFDirectoryEntryPage(Page): +class COFDirectoryEntryPage(AbsoluteURLMixin, Page): body = RichTextField("Description") links = StreamField( [