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 14 additions and 11 deletions
Showing only changes of commit 737a3e377c - Show all commits

View file

@ -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/"

View file

@ -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