Files
lms/community/www/courses/course.py
Anand Chitipothu bfc15cf1a4 Added preview and sections fields to LMS Topic
- The preview is used to show the details of the topic in the course page
- the sections are used to show the different part of the topic, each could be of a different type

Issue #8
2021-03-05 17:20:02 +00:00

37 lines
904 B
Python

import frappe
def get_context(context):
context.no_cache = 1
try:
course_id = frappe.form_dict['course']
except KeyError:
frappe.local.flags.redirect_location = '/courses'
raise frappe.Redirect
context.course = get_course(course_id)
context.course_enrolled = has_enrolled(course_id)
def get_course(name):
course = frappe.db.get_value('LMS Course', name,
['name', 'title', 'description'], as_dict=1)
course['topics'] = frappe.db.get_all('LMS Topic',
filters={
'course': name
},
fields=['name', 'title', 'preview'],
order_by='creation'
)
return course
@frappe.whitelist()
def has_enrolled(course):
return frappe.db.get_value("LMS Course Enrollment", {"course": course, "owner": frappe.session.user})
@frappe.whitelist()
def enroll(course):
return frappe.get_doc({
"doctype": "LMS Course Enrollment",
"course": course,
"user": frappe.session.user
}).save()