blob: 78b02e27786abd41ec617bde276eab7266b1d5b1 [file] [log] [blame]
Shivam Mishrac8c790a2019-05-21 12:04:50 +05301from __future__ import unicode_literals
2import erpnext.education.utils as utils
3import frappe
4
5no_cache = 1
6
7def get_context(context):
Shivam Mishraae2871f2019-05-29 13:11:34 +05308 if frappe.session.user == "Guest":
9 frappe.local.flags.redirect_location = '/lms'
10 raise frappe.Redirect
11
Shivam Mishrac8c790a2019-05-21 12:04:50 +053012 context.course = frappe.form_dict['course']
13 context.topic = frappe.form_dict['topic']
14 content = frappe.form_dict['content']
15 context.content_type = frappe.form_dict['type']
16
17 context.content = frappe.get_doc(context.content_type, content).as_dict()
Shivam Mishrac8c790a2019-05-21 12:04:50 +053018 context.previous = get_previous_content(context.topic, context.course, context.content, context.content_type)
Shivam Mishrac8c790a2019-05-21 12:04:50 +053019 context.next = get_next_content(context.topic, context.course, context.content, context.content_type)
20
21def get_next_content(topic, course, content, content_type):
22 if frappe.session.user == "Guest":
23 return None
24 topic = frappe.get_doc("Topic", topic)
25 content_list = [{'content_type':item.doctype, 'content':item.name} for item in topic.get_contents()]
26 current_index = content_list.index({'content': content.name, 'content_type': content_type})
27 try:
28 return content_list[current_index + 1]
29 except IndexError:
30 return None
31
32def get_previous_content(topic, course, content, content_type):
33 if frappe.session.user == "Guest":
34 return None
35 topic = frappe.get_doc("Topic", topic)
36 content_list = [{'content_type':item.doctype, 'content':item.name} for item in topic.get_contents()]
37 current_index = content_list.index({'content': content.name, 'content_type': content_type})
38 if current_index == 0:
39 return None
40 else:
41 return content_list[current_index - 1]