2019-05-21 06:34:50 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
import erpnext.education.utils as utils
|
|
|
|
import frappe
|
|
|
|
|
|
|
|
no_cache = 1
|
|
|
|
|
|
|
|
def get_context(context):
|
2019-05-29 07:41:34 +00:00
|
|
|
if frappe.session.user == "Guest":
|
|
|
|
frappe.local.flags.redirect_location = '/lms'
|
|
|
|
raise frappe.Redirect
|
|
|
|
|
2019-05-21 06:34:50 +00:00
|
|
|
context.course = frappe.form_dict['course']
|
|
|
|
context.topic = frappe.form_dict['topic']
|
|
|
|
content = frappe.form_dict['content']
|
|
|
|
context.content_type = frappe.form_dict['type']
|
|
|
|
|
|
|
|
context.content = frappe.get_doc(context.content_type, content).as_dict()
|
|
|
|
context.previous = get_previous_content(context.topic, context.course, context.content, context.content_type)
|
|
|
|
context.next = get_next_content(context.topic, context.course, context.content, context.content_type)
|
|
|
|
|
|
|
|
def get_next_content(topic, course, content, content_type):
|
|
|
|
if frappe.session.user == "Guest":
|
|
|
|
return None
|
|
|
|
topic = frappe.get_doc("Topic", topic)
|
|
|
|
content_list = [{'content_type':item.doctype, 'content':item.name} for item in topic.get_contents()]
|
|
|
|
current_index = content_list.index({'content': content.name, 'content_type': content_type})
|
|
|
|
try:
|
|
|
|
return content_list[current_index + 1]
|
|
|
|
except IndexError:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_previous_content(topic, course, content, content_type):
|
|
|
|
if frappe.session.user == "Guest":
|
|
|
|
return None
|
|
|
|
topic = frappe.get_doc("Topic", topic)
|
|
|
|
content_list = [{'content_type':item.doctype, 'content':item.name} for item in topic.get_contents()]
|
|
|
|
current_index = content_list.index({'content': content.name, 'content_type': content_type})
|
|
|
|
if current_index == 0:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return content_list[current_index - 1]
|