diff --git a/lms/hooks.py b/lms/hooks.py
index 8a0fd55e..ce08b4bd 100644
--- a/lms/hooks.py
+++ b/lms/hooks.py
@@ -12,8 +12,12 @@ app_color = "grey"
app_email = "jannat@frappe.io"
app_license = "AGPL"
-lms_path = frappe.conf.get("lms_path") or "lms"
-app_icon_route = f"/{lms_path}"
+
+def get_lms_path():
+ return (frappe.conf.get("lms_path") or "lms").strip("/")
+
+
+app_icon_route = f"/{get_lms_path()}"
# Includes in
# ------------------
@@ -167,8 +171,8 @@ override_whitelisted_methods = {
# Add all simple route rules here
website_route_rules = [
- {"from_route": f"/{lms_path}/", "to_route": "_lms"},
- {"from_route": f"/{lms_path}", "to_route": "_lms"},
+ {"from_route": f"/{get_lms_path()}/", "to_route": "_lms"},
+ {"from_route": f"/{get_lms_path()}", "to_route": "_lms"},
{
"from_route": "/courses//",
"to_route": "certificate",
@@ -177,25 +181,25 @@ website_route_rules = [
website_redirects = [
{"source": "/update-profile", "target": "/edit-profile"},
- {"source": "/courses", "target": f"/{lms_path}/courses"},
+ {"source": "/courses", "target": f"/{get_lms_path()}/courses"},
{
"source": r"^/courses/.*$",
- "target": f"/{lms_path}/courses",
+ "target": f"/{get_lms_path()}/courses",
},
- {"source": "/batches", "target": f"/{lms_path}/batches"},
+ {"source": "/batches", "target": f"/{get_lms_path()}/batches"},
{
"source": r"/batches/(.*)",
- "target": f"/{lms_path}/batches",
+ "target": f"/{get_lms_path()}/batches",
"match_with_query_string": True,
},
- {"source": "/job-openings", "target": f"/{lms_path}/job-openings"},
+ {"source": "/job-openings", "target": f"/{get_lms_path()}/job-openings"},
{
"source": r"/job-openings/(.*)",
- "target": f"/{lms_path}/job-openings",
+ "target": f"/{get_lms_path()}/job-openings",
"match_with_query_string": True,
},
- {"source": "/statistics", "target": f"/{lms_path}/statistics"},
- {"source": "_lms", "target": f"/{lms_path}"},
+ {"source": "/statistics", "target": f"/{get_lms_path()}/statistics"},
+ {"source": "_lms", "target": f"/{get_lms_path()}"},
]
update_website_context = [
@@ -267,7 +271,7 @@ add_to_apps_screen = [
"name": "lms",
"logo": "/assets/lms/frontend/learning.svg",
"title": "Learning",
- "route": f"/{lms_path}",
+ "route": f"/{get_lms_path()}",
"has_permission": "lms.lms.api.check_app_permission",
}
]
diff --git a/lms/lms/api.py b/lms/lms/api.py
index 731c0dde..faee30ce 100644
--- a/lms/lms/api.py
+++ b/lms/lms/api.py
@@ -28,7 +28,6 @@ from frappe.utils import (
)
from frappe.utils.response import Response
-from lms.hooks import lms_path
from lms.lms.doctype.course_lesson.course_lesson import save_progress
from lms.lms.utils import (
get_average_rating,
@@ -36,6 +35,7 @@ from lms.lms.utils import (
get_course_details,
get_instructors,
get_lesson_count,
+ get_lms_route,
)
@@ -1674,7 +1674,7 @@ def get_pwa_manifest():
"name": title,
"short_name": title,
"description": "Easy to use, 100% open source Learning Management System",
- "start_url": f"/{lms_path}",
+ "start_url": get_lms_route(),
"icons": [
{
"src": banner_image or "/assets/lms/frontend/manifest/manifest-icon-192.maskable.png",
diff --git a/lms/lms/test_utils.py b/lms/lms/test_utils.py
index cbfe8640..c786a8b7 100644
--- a/lms/lms/test_utils.py
+++ b/lms/lms/test_utils.py
@@ -2,7 +2,6 @@ import frappe
from frappe.tests import UnitTestCase
from frappe.utils import add_days, nowdate
-from lms.hooks import lms_path
from lms.lms.api import get_certified_participants
from lms.lms.doctype.lms_certificate.lms_certificate import get_default_certificate_template, is_certified
@@ -14,6 +13,7 @@ from .utils import (
get_lesson_index,
get_lesson_url,
get_lessons,
+ get_lms_route,
get_membership,
get_reviews,
get_tags,
@@ -236,7 +236,7 @@ class TestUtils(UnitTestCase):
def test_get_lesson_url(self):
lessons = get_lessons(self.course.name)
for lesson in lessons:
- expected_url = f"/{lms_path}/courses/{self.course.name}/learn/{lesson.number}"
+ expected_url = get_lms_route(f"courses/{self.course.name}/learn/{lesson.number}")
self.assertEqual(get_lesson_url(self.course.name, lesson.number), expected_url)
def test_is_instructor(self):
diff --git a/lms/lms/user.py b/lms/lms/user.py
index d89455ce..d6535977 100644
--- a/lms/lms/user.py
+++ b/lms/lms/user.py
@@ -4,8 +4,7 @@ from frappe.model.naming import append_number_if_name_exists
from frappe.utils import escape_html, random_string
from frappe.website.utils import cleanup_page_name, is_signup_disabled
-from lms.hooks import lms_path
-from lms.lms.utils import get_country_code
+from lms.lms.utils import get_country_code, get_lms_route
def validate_username_duplicates(doc, method):
@@ -89,4 +88,4 @@ def set_country_from_ip(login_manager=None, user=None):
def on_login(login_manager):
default_app = frappe.db.get_single_value("System Settings", "default_app")
if default_app == "lms":
- frappe.local.response["home_page"] = f"/{lms_path}"
+ frappe.local.response["home_page"] = get_lms_route()
diff --git a/lms/www/_lms.py b/lms/www/_lms.py
index 10a9b796..1aca0b9f 100644
--- a/lms/www/_lms.py
+++ b/lms/www/_lms.py
@@ -5,8 +5,7 @@ from bs4 import BeautifulSoup
from frappe import _
from frappe.utils.telemetry import capture
-from lms.hooks import lms_path
-from lms.lms.utils import get_lms_route
+from lms.lms.utils import get_lms_path, get_lms_route
no_cache = 1
@@ -35,7 +34,7 @@ def get_boot():
"read_only_mode": frappe.flags.read_only,
"csrf_token": frappe.sessions.get_csrf_token(),
"site_name": frappe.local.site,
- "lms_path": lms_path,
+ "lms_path": get_lms_path(),
}
)