From 541a522b26bc2c5fedf050fd63755fb7ee3dd1b5 Mon Sep 17 00:00:00 2001 From: scmmishra Date: Thu, 18 Oct 2018 15:41:50 +0530 Subject: [PATCH] LMS:Added class methods for course, program and student doctypes Co-authored-by: Chinmay Pai --- erpnext/education/doctype/course/course.py | 15 ++++++++++++--- erpnext/education/doctype/program/program.py | 6 +++++- erpnext/education/doctype/student/student.py | 10 ++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/erpnext/education/doctype/course/course.py b/erpnext/education/doctype/course/course.py index 68d666c5d0..1e4270954d 100644 --- a/erpnext/education/doctype/course/course.py +++ b/erpnext/education/doctype/course/course.py @@ -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 \ No newline at end of file diff --git a/erpnext/education/doctype/program/program.py b/erpnext/education/doctype/program/program.py index f626880b2a..38bdb8129b 100644 --- a/erpnext/education/doctype/program/program.py +++ b/erpnext/education/doctype/program/program.py @@ -7,4 +7,8 @@ import frappe from frappe.model.document import Document class Program(Document): - pass \ No newline at end of file + + 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 \ No newline at end of file diff --git a/erpnext/education/doctype/student/student.py b/erpnext/education/doctype/student/student.py index 53bf6f7273..59c1a498e4 100644 --- a/erpnext/education/doctype/student/student.py +++ b/erpnext/education/doctype/student/student.py @@ -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(*)