From a3788a0f392e8cbb905f13d3a679a1cc0b1fd7d7 Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Tue, 6 Apr 2021 18:36:07 +0530 Subject: [PATCH] refactor: added nice urls for sketches. - Sketches will be available at `/sketches/` --- community/hooks.py | 2 ++ .../lms/doctype/lms_sketch/lms_sketch.py | 8 +++++ community/www/sketches/index.html | 4 +-- community/www/sketches/sketch.py | 29 +++++++++++-------- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/community/hooks.py b/community/hooks.py index dff32fe2..7669e2fe 100644 --- a/community/hooks.py +++ b/community/hooks.py @@ -132,7 +132,9 @@ install_regex_converter() # 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"} diff --git a/community/lms/doctype/lms_sketch/lms_sketch.py b/community/lms/doctype/lms_sketch/lms_sketch.py index 21257e49..2f0120fe 100644 --- a/community/lms/doctype/lms_sketch/lms_sketch.py +++ b/community/lms/doctype/lms_sketch/lms_sketch.py @@ -13,6 +13,14 @@ class LMSSketch(Document): def get_owner_name(self): return get_userinfo(self.owner)['full_name'] + @property + def sketch_id(self): + """Returns the numeric part of the name. + + For example, the skech_id will be "123" for sketch with name "SKETCH-123". + """ + return self.name.replace("SKETCH-", "") + def get_livecode_url(self): doc = frappe.get_cached_doc("LMS Settings") return doc.livecode_url diff --git a/community/www/sketches/index.html b/community/www/sketches/index.html index 2a6381f0..dd1a61de 100644 --- a/community/www/sketches/index.html +++ b/community/www/sketches/index.html @@ -21,13 +21,13 @@