Added functions to query Student enrollments

This commit is contained in:
scmmishra 2018-11-03 19:31:53 +05:30 committed by Aditya Hase
parent 91aa0e07c8
commit 73a31ec7bb
2 changed files with 66 additions and 11 deletions

View File

@ -46,14 +46,31 @@ class Student(Document):
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))
course_enrollments = frappe.get_list("Course Enrollment", filters={"student": self.name}, fields=['name'])
if not course_enrollments:
return None
else:
enrollments= [frappe.get_doc("Course Enrollment", enrollment.name) for enrollment in enrollments_name_list]
enrollments = [item['name'] for item in course_enrollments]
return enrollments
def get_program_enrollments(self):
"""Returns a list of course enrollments linked with the current student"""
program_enrollments = frappe.get_list("Program Enrollment", filters={"student": self.name}, fields=['program'])
if not program_enrollments:
return None
else:
enrollments = [item['program'] for item in program_enrollments]
return enrollments
def get_completed_courses(self):
"""Returns a list of course enrollments linked with the current student"""
completed_courses = frappe.get_list("Course Enrollment", filters={"student": self.name, "completed":1}, fields=['course'])
if not completed_courses:
return None
else:
courses = [item['course'] for item in completed_courses]
return courses
def enroll_in_program(self, program_name):
enrollment = frappe.get_doc({
"doctype": "Program Enrollment",
@ -65,6 +82,18 @@ class Student(Document):
enrollment.save()
enrollment.submit()
frappe.db.commit()
return enrollment
def enroll_in_course(self, course_name, program_enrollment, enrollment_date=frappe.utils.datetime.datetime.now()):
enrollment = frappe.get_doc({
"doctype": "Course Enrollment",
"student": self.name,
"course": course_name,
"program_enrollment": program_enrollment,
"enrollment_date": enrollment_date
})
enrollment.save()
frappe.db.commit()
def get_timeline_data(doctype, name):
'''Return timeline for attendance'''

View File

@ -105,8 +105,13 @@ def evaluate_quiz(quiz_response, quiz_name):
# return None
@frappe.whitelist()
def get_completed_courses():
return ['ECP-001', 'ECP-002']
def get_completed_courses(email=frappe.session.user):
try:
print(email)
student = frappe.get_doc("Student", get_student_id(email))
return student.get_completed_courses()
except:
return None
@frappe.whitelist()
def get_continue_data(program_name):
@ -127,15 +132,20 @@ def create_student(student_name=frappe.session.user):
return student_name
@frappe.whitelist()
def enroll(type, name, student_email_id):
def enroll_all_courses_in_program(program_enrollment, student):
course_list = [course.name for course in get_courses(program_enrollment.program)]
for course_name in course_list:
student.enroll_in_course(course_name=course_name, program_enrollment=program_enrollment.name)
@frappe.whitelist()
def enroll_in_program(program_name, student_email_id):
if(not get_student_id(student_email_id)):
create_student(student_email_id)
student = frappe.get_doc("Student", get_student_id(student_email_id))
if type == "Program":
student.enroll_in_program(name)
if type == "Course":
pass
program_enrollment = student.enroll_in_program(program_name)
enroll_all_courses_in_program(program_enrollment, student)
@frappe.whitelist()
def get_student_id(email=None):
"""Returns student user name, example EDU-STU-2018-00001 (Based on the naming series).
@ -144,4 +154,20 @@ def get_student_id(email=None):
try:
return frappe.get_all('Student', filters={'student_email_id': email}, fields=['name'])[0].name
except IndexError:
return None
@frappe.whitelist()
def get_program_enrollments(email=frappe.session.user):
try:
student = frappe.get_doc("Student", get_student_id(email))
return student.get_program_enrollments()
except:
return None
@frappe.whitelist()
def get_course_enrollments(email=frappe.session.user):
try:
student = frappe.get_doc("Student", get_student_id(email))
return student.get_course_enrollments()
except:
return None