LMS:Added class methods for course, program and student doctypes

Co-authored-by: Chinmay Pai <chinmaydpai@gmail.com>
This commit is contained in:
scmmishra 2018-10-18 15:41:50 +05:30 committed by Aditya Hase
parent 1869419bdc
commit 541a522b26
3 changed files with 27 additions and 4 deletions

View File

@ -19,7 +19,7 @@ class Course(Document):
if total_weightage != 100:
frappe.throw(_("Total Weightage of all Assessment Criteria must be 100%"))
def get_content_data(self, data):
def get_content_value(self, data):
try:
course_content_list = self.get_all_children()
content_data = [frappe.get_value(course_content.content_type, course_content.content, data) for course_content in course_content_list]
@ -28,9 +28,18 @@ class Course(Document):
return None
return content_data
def get_content_info(self):
try:
course_content_list = self.get_all_children()
content_data = [[course_content.content_type, course_content.content] for course_content in course_content_list]
except Exception as e:
print(e)
return None
return content_data
def get_content_title(self):
'''
returns all the course content for the given course object.
'''
content_title = self.get_content_data("title")
return content_title
content_title = self.get_content_value("title")
return content_title

View File

@ -7,4 +7,8 @@ import frappe
from frappe.model.document import Document
class Program(Document):
pass
def get_course_list(self):
course_content_list = self.get_all_children()
course_list = [frappe.get_doc("Course", course_item.course) for course_item in course_content_list]
return course_list

View File

@ -44,6 +44,16 @@ class Student(Document):
if self.student_applicant:
frappe.db.set_value("Student Applicant", self.student_applicant, "application_status", "Admitted")
def get_course_enrollments(self):
"""Returns a list of course enrollments linked with the current student"""
enrollments_name_list = frappe.get_list("Course Enrollment", filters={"student": self.name}, fields=['name'])
if not enrollments_name_list:
frappe.throw("Student {0} has not enrolled in any course".format(self.name))
return None
else:
enrollments= [frappe.get_doc("Course Enrollment", enrollment.name) for enrollment in enrollments_name_list]
return enrollments
def get_timeline_data(doctype, name):
'''Return timeline for attendance'''
return dict(frappe.db.sql('''select unix_timestamp(`date`), count(*)