Sitecof: Récriture des URLs publiques #752
2 changed files with 30 additions and 6 deletions
|
@ -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 = r"/\\1news/"
|
||||
|
|
|
@ -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(
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue