|
|
@@ -1,5 +1,6 @@ |
|
|
|
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors |
|
|
|
# License: MIT. See LICENSE |
|
|
|
import re |
|
|
|
from urllib.parse import quote |
|
|
|
|
|
|
|
import frappe |
|
|
@@ -16,6 +17,7 @@ class WebsiteSettings(Document): |
|
|
|
self.validate_footer_items() |
|
|
|
self.validate_home_page() |
|
|
|
self.validate_google_settings() |
|
|
|
self.validate_redirects() |
|
|
|
|
|
|
|
def validate_home_page(self): |
|
|
|
if frappe.flags.in_install: |
|
|
@@ -72,6 +74,16 @@ class WebsiteSettings(Document): |
|
|
|
if self.enable_google_indexing and not frappe.db.get_single_value("Google Settings", "enable"): |
|
|
|
frappe.throw(_("Enable Google API in Google Settings.")) |
|
|
|
|
|
|
|
def validate_redirects(self): |
|
|
|
for idx, row in enumerate(self.route_redirects): |
|
|
|
try: |
|
|
|
source = row.source.strip("/ ") + "$" |
|
|
|
re.compile(source) |
|
|
|
re.sub(source, row.target, "") |
|
|
|
except Exception as e: |
|
|
|
if not frappe.flags.in_migrate: |
|
|
|
frappe.throw(_("Invalid redirect regex in row #{}: {}").format(idx, str(e))) |
|
|
|
|
|
|
|
def on_update(self): |
|
|
|
self.clear_cache() |
|
|
|
|
|
|
|