Compare commits

...

3 commits

Author SHA1 Message Date
Robin Champenois
d1f5cb6840 Print oublié 2020-08-30 12:48:47 +02:00
Evarin
737a3e377c Sitecof : Surcharge get_url_parts plutôt que get_url 2020-08-30 11:59:02 +02:00
Evarin
a59711183d Sitecof: Rewrite public URLs 2020-08-30 11:31:44 +02:00
2 changed files with 32 additions and 6 deletions

View file

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

View file

@ -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,22 @@ 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_parts(self, request=None, current_site=None):
(site_id, root_url, page_path) = super().get_url_parts(request)
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/")
page_path = re.sub(pattern, replace, page_path)
return (site_id, root_url, page_path)
# Page pouvant afficher des actualités
class COFActuIndexMixin:
@property
@ -18,7 +37,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 +81,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 +102,7 @@ class COFPage(Page):
# Actualités
class COFActuIndexPage(Page, COFActuIndexMixin):
class COFActuIndexPage(COFRewriteUrlMixin, Page, COFActuIndexMixin):
subpage_types = ["COFActuPage"]
parent_page_types = ["COFRootPage"]
@ -108,7 +127,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 +164,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 +190,7 @@ class COFDirectoryPage(Page):
verbose_name_plural = "Annuaires"
class COFDirectoryEntryPage(Page):
class COFDirectoryEntryPage(COFRewriteUrlMixin, Page):
body = RichTextField("Description")
links = StreamField(
[