From 147d5d9bf2128291d46fa539e81d3f4e8d8c178b Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 12 Jun 2019 16:01:02 +0530 Subject: [PATCH] fix: redirect to lms home if query params not set --- erpnext/www/lms/course.py | 11 +++++++++-- erpnext/www/lms/program.py | 10 ++++++++-- erpnext/www/lms/topic.py | 10 +++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/erpnext/www/lms/course.py b/erpnext/www/lms/course.py index e7ed2e3ed6..c18d64e507 100644 --- a/erpnext/www/lms/course.py +++ b/erpnext/www/lms/course.py @@ -5,9 +5,16 @@ import frappe no_cache = 1 def get_context(context): + try: + program = frappe.form_dict['program'] + course_name = frappe.form_dict['name'] + except KeyError: + frappe.local.flags.redirect_location = '/lms' + raise frappe.Redirect + context.education_settings = frappe.get_single("Education Settings") - course = frappe.get_doc('Course', frappe.form_dict['name']) - context.program = frappe.form_dict['program'] + course = frappe.get_doc('Course', course_name) + context.program = program context.course = course context.topics = course.get_topics() diff --git a/erpnext/www/lms/program.py b/erpnext/www/lms/program.py index 1fcb3d3028..7badedcc85 100644 --- a/erpnext/www/lms/program.py +++ b/erpnext/www/lms/program.py @@ -6,10 +6,16 @@ from frappe import _ no_cache = 1 def get_context(context): + try: + program = frappe.form_dict['program'] + except KeyError: + frappe.local.flags.redirect_location = '/lms' + raise frappe.Redirect + context.education_settings = frappe.get_single("Education Settings") - context.program = get_program(frappe.form_dict['program']) + context.program = get_program(program) context.courses = [frappe.get_doc("Course", course.course) for course in context.program.courses] - context.has_access = utils.allowed_program_access(frappe.form_dict['program']) + context.has_access = utils.allowed_program_access(program) context.progress = get_course_progress(context.courses, context.program) def get_program(program_name): diff --git a/erpnext/www/lms/topic.py b/erpnext/www/lms/topic.py index 0af0778312..f75ae8e9b6 100644 --- a/erpnext/www/lms/topic.py +++ b/erpnext/www/lms/topic.py @@ -5,9 +5,13 @@ import frappe no_cache = 1 def get_context(context): - course = frappe.form_dict['course'] - program = frappe.form_dict['program'] - topic = frappe.form_dict['topic'] + try: + course = frappe.form_dict['course'] + program = frappe.form_dict['program'] + topic = frappe.form_dict['topic'] + except KeyError: + frappe.local.flags.redirect_location = '/lms' + raise frappe.Redirect context.program = program context.course = course