Show 404 page when the topic is not found.
Earlier it was failing with internal error.
This commit is contained in:
@@ -2,12 +2,16 @@ import frappe
|
|||||||
|
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
context.no_cache = 1
|
context.no_cache = 1
|
||||||
course_name = get_queryparam("course", '/courses')
|
|
||||||
context.course = get_course(course_name)
|
|
||||||
|
|
||||||
topic_name = get_queryparam("topic", '/courses?course=' + course_name)
|
try:
|
||||||
context.topic = get_topic(course_name, topic_name)
|
course_name = get_queryparam("course", '/courses')
|
||||||
context.livecode_url = get_livecode_url()
|
context.course = get_course(course_name)
|
||||||
|
|
||||||
|
topic_name = get_queryparam("topic", '/courses/' + course_name)
|
||||||
|
context.topic = get_topic(course_name, topic_name)
|
||||||
|
context.livecode_url = get_livecode_url()
|
||||||
|
except frappe.DoesNotExistError:
|
||||||
|
context.template = 'www/404.html'
|
||||||
|
|
||||||
def get_livecode_url():
|
def get_livecode_url():
|
||||||
doc = frappe.get_doc("LMS Settings")
|
doc = frappe.get_doc("LMS Settings")
|
||||||
@@ -23,15 +27,15 @@ def get_queryparam(name, redirect_when_not_found):
|
|||||||
def get_course(name):
|
def get_course(name):
|
||||||
try:
|
try:
|
||||||
course = frappe.get_doc('LMS Course', name)
|
course = frappe.get_doc('LMS Course', name)
|
||||||
except frappe.exceptions.DoesNotExistError:
|
except frappe.DoesNotExistError:
|
||||||
raise frappe.NotFound
|
raise
|
||||||
return course
|
return course
|
||||||
|
|
||||||
def get_topic(course_name, topic_name):
|
def get_topic(course_name, topic_name):
|
||||||
try:
|
try:
|
||||||
topic = frappe.get_doc('LMS Topic', topic_name)
|
topic = frappe.get_doc('LMS Topic', topic_name)
|
||||||
except frappe.exceptions.DoesNotExistError:
|
except frappe.DoesNotExistError:
|
||||||
raise frappe.NotFound
|
raise
|
||||||
if topic.course != course_name:
|
if topic.course != course_name:
|
||||||
raise frappe.NotFound
|
raise frappe.DoesNotExistError()
|
||||||
return topic
|
return topic
|
||||||
|
|||||||
Reference in New Issue
Block a user