Sitecof: Récriture des URLs publiques #752

Closed
champeno wants to merge 3 commits from Evarin/sitecof-rewrite-urls into master
2 changed files with 30 additions and 6 deletions
Showing only changes of commit a59711183d - Show all commits

View file

@ -201,3 +201,10 @@ MAIL_DATA = {
"REPLYTO": "BdA-Revente <bda-revente@ens.fr>", "REPLYTO": "BdA-Revente <bda-revente@ens.fr>",
}, },
} }
# ---
# SiteCOF URL rewrite rules
# ---
SITECOF_INTERNAL_URL = r"/gestion/(en/|fr/|)sitecof/"
SITECOF_PUBLIC_URL = r"/\\1news/"

View file

@ -1,3 +1,6 @@
import re
from django.conf import settings
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel 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 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 # Page pouvant afficher des actualités
class COFActuIndexMixin: class COFActuIndexMixin:
@property @property
@ -18,7 +35,7 @@ class COFActuIndexMixin:
# Racine du site du COF # Racine du site du COF
class COFRootPage(RoutablePageMixin, Page, COFActuIndexMixin): class COFRootPage(COFRewriteUrlMixin, RoutablePageMixin, Page, COFActuIndexMixin):
introduction = RichTextField("Introduction") introduction = RichTextField("Introduction")
content_panels = Page.content_panels + [ content_panels = Page.content_panels + [
@ -62,7 +79,7 @@ class IFrameBlock(blocks.StructBlock):
# Page lambda du site # Page lambda du site
class COFPage(Page): class COFPage(COFRewriteUrlMixin, Page):
body = StreamField( body = StreamField(
[ [
("heading", blocks.CharBlock(classname="full title")), ("heading", blocks.CharBlock(classname="full title")),
@ -83,7 +100,7 @@ class COFPage(Page):
# Actualités # Actualités
class COFActuIndexPage(Page, COFActuIndexMixin): class COFActuIndexPage(COFRewriteUrlMixin, Page, COFActuIndexMixin):
subpage_types = ["COFActuPage"] subpage_types = ["COFActuPage"]
parent_page_types = ["COFRootPage"] parent_page_types = ["COFRootPage"]
@ -108,7 +125,7 @@ class COFActuIndexPage(Page, COFActuIndexMixin):
return context return context
class COFActuPage(RoutablePageMixin, Page): class COFActuPage(COFRewriteUrlMixin, RoutablePageMixin, Page):
chapo = models.TextField("Description rapide", blank=True) chapo = models.TextField("Description rapide", blank=True)
body = RichTextField("Contenu") body = RichTextField("Contenu")
image = models.ForeignKey( image = models.ForeignKey(
@ -145,7 +162,7 @@ class COFActuPage(RoutablePageMixin, Page):
# Annuaires (Clubs, partenaires, bonnes adresses) # Annuaires (Clubs, partenaires, bonnes adresses)
class COFDirectoryPage(Page): class COFDirectoryPage(COFRewriteUrlMixin, Page):
introduction = RichTextField("Introduction") introduction = RichTextField("Introduction")
alphabetique = models.BooleanField( alphabetique = models.BooleanField(
"Tri par ordre alphabétique ?", default=True, blank=True "Tri par ordre alphabétique ?", default=True, blank=True
@ -171,7 +188,7 @@ class COFDirectoryPage(Page):
verbose_name_plural = "Annuaires" verbose_name_plural = "Annuaires"
class COFDirectoryEntryPage(Page): class COFDirectoryEntryPage(COFRewriteUrlMixin, Page):
body = RichTextField("Description") body = RichTextField("Description")
links = StreamField( links = StreamField(
[ [