From b8b767398544c9699d06d411e6db69d13dc8db98 Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Wed, 7 Apr 2021 12:41:17 +0530 Subject: [PATCH] fix: added a work-around to the issue of regex converter not loaded. frappe app doesn't load all python modules of all the apps on startup. It loads the hooks.py only if it is not already cached. Because of this the code to install the regex coverter to not running, causing errors. Fixed it by replacing the regex route with a string route. The issue is it also matches the paths like `socket.io` and `website_script.js` etc. Handled that by whitelisting those routes. --- community/__init__.py | 3 --- community/hooks.py | 11 +++++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/community/__init__.py b/community/__init__.py index 65fc9069..43b477a7 100644 --- a/community/__init__.py +++ b/community/__init__.py @@ -3,8 +3,5 @@ from __future__ import unicode_literals __version__ = '0.0.1' -from .routing import install_regex_converter -install_regex_converter() - # load the methods from the lms api from .lms import api # noqa diff --git a/community/hooks.py b/community/hooks.py index bdc9e026..5cbe5f72 100644 --- a/community/hooks.py +++ b/community/hooks.py @@ -129,9 +129,7 @@ scheduler_events = { # Add all simple route rules here primary_rules = [ - {"from_route": "/sketches", "to_route": "sketches"}, {"from_route": "/sketches/", "to_route": "sketches/sketch"}, - {"from_route": "/courses", "to_route": "courses"}, {"from_route": "/courses/", "to_route": "courses/course"}, {"from_route": "/courses//", "to_route": "courses/topic"}, {"from_route": "/courses//", "to_route": "courses/topic"} @@ -142,13 +140,18 @@ whitelist = [ "/login", "/update-password", "/update-profile", - "/third-party-apps" + "/third-party-apps", + "/website_script.js", + "/courses", + "/sketches", + "/admin", + "/socket.io", ] whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist] # regex rule to match all profiles profile_rules = [ - {"from_route": "/", "to_route": "profiles/profile"}, + {"from_route": "/", "to_route": "profiles/profile"}, ] website_route_rules = primary_rules + whitelist_rules + profile_rules