chore: renamed `get_program` api functions
- `get_program` is renamed to `get_program_and_enrollment_status`
- `get_program_detail` is renamed to `get_program`
- Minor code improvements
diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py
index 5aaaa2f..7a61ae5 100644
--- a/erpnext/education/utils.py
+++ b/erpnext/education/utils.py
@@ -89,7 +89,7 @@
else:
return None
-def get_program(program_name):
+def get_program_and_enrollment_status(program_name):
program = frappe.get_doc('Program', program_name)
is_enrolled = bool(get_program_enrollment(program_name)) or check_super_access()
return {'program': program, 'is_enrolled': is_enrolled}
diff --git a/erpnext/public/js/education/lms/pages/ProgramPage.vue b/erpnext/public/js/education/lms/pages/ProgramPage.vue
index 3f3a0f7..2a13661 100644
--- a/erpnext/public/js/education/lms/pages/ProgramPage.vue
+++ b/erpnext/public/js/education/lms/pages/ProgramPage.vue
@@ -35,7 +35,7 @@
},
methods: {
getProgramDetails() {
- return lms.call('get_program_details', {
+ return lms.call('get_program', {
program_name: this.program_name
});
},
diff --git a/erpnext/www/lms.py b/erpnext/www/lms.py
index dc3b671..801d766 100644
--- a/erpnext/www/lms.py
+++ b/erpnext/www/lms.py
@@ -34,7 +34,7 @@
def get_featured_programs():
featured_program_names = frappe.get_all("Program", filters={"is_published": True, "is_featured": True})
if featured_program_names:
- featured_list = [utils.get_program(program['name']) for program in featured_program_names]
+ featured_list = [utils.get_program_and_enrollment_status(program['name']) for program in featured_program_names]
return featured_list
else:
return get_all_programs()[:2]
@@ -43,18 +43,15 @@
def get_all_programs():
program_names = frappe.get_all("Program", filters={"is_published": True})
if program_names:
- program_list = [utils.get_program(program['name']) for program in program_names]
+ program_list = [utils.get_program_and_enrollment_status(program['name']) for program in program_names]
return program_list
- else:
- return None
@frappe.whitelist(allow_guest=True)
-def get_program_details(program_name):
+def get_program(program_name):
try:
- program = frappe.get_doc('Program', program_name)
- return program
- except:
- return None
+ return frappe.get_doc('Program', program_name)
+ except frappe.DoesNotExistError:
+ frappe.throw(_("Program {0} does not exist.".format(program_name)))
# Functions to get program & course details
@frappe.whitelist(allow_guest=True)