create course enrollment if not already enrolled for a program

This commit is contained in:
scmmishra 2018-11-26 14:41:15 +05:30 committed by Aditya Hase
parent affbfe7d0c
commit 97c994f394
3 changed files with 22 additions and 10 deletions

View File

@ -109,7 +109,12 @@ def create_student():
})
student.save(ignore_permissions=True)
frappe.db.commit()
return student_name
return student
def enroll_in_course(course_name, program_name):
student_id = get_current_student()
student = frappe.get_doc("Student", student_id)
student.enroll_in_course(course_name=course_name, program_enrollment=get_program_enrollment(program_name))
def enroll_all_courses_in_program(program_enrollment, student):
program = frappe.get_doc("Program", program_enrollment.program)

View File

@ -67,7 +67,7 @@ export default {
},
isLogin() {
return lms.store.checkLogin()
}
},
},
methods: {
iconClass(content_type) {
@ -77,9 +77,10 @@ export default {
},
getCourseMeta() {
return lms.call('get_course_meta', {
course_name: this.course.name
course_name: this.course.name,
program_name: this.program_name
})
}
},
}
};
</script>
@ -92,6 +93,7 @@ export default {
}
li {
list-style-type: none;
padding: 0;
}
.fa {
font-size: 0.8em;

View File

@ -199,9 +199,10 @@ def check_quiz_completion(quiz, enrollment_name):
return status, score, result
@frappe.whitelist()
def get_course_meta(course_name):
def get_course_meta(course_name, program_name):
course_enrollment = utils.get_course_enrollment(course_name)
# course_enrollment = frappe.get_doc("Course Enrollment", course_enrollment_name)
if not course_enrollment:
utils.enroll_in_course(course_name, program_name)
progress = get_course_progress(course_enrollment)
count = sum([act['is_complete'] for act in progress])
if count == 0:
@ -215,7 +216,11 @@ def get_course_meta(course_name):
@frappe.whitelist()
def get_program_meta(program_name):
program = frappe.get_doc("Program", program_name)
program_meta = {}
for course in program.get_all_children():
program_meta[course.course] = get_course_meta(course.course)
return program_meta
program_enrollment = frappe.get_list("Program Enrollment", filters={'student': utils.get_current_student(), 'program': program_name })[0].name
if not program_enrollment:
return None
else:
program_meta = {}
for course in program.get_all_children():
program_meta[course.course] = get_course_meta(course.course, program_name)
return program_meta