From 8fa9adec37fb1676fcb0a968801d2446015feb85 Mon Sep 17 00:00:00 2001 From: scmmishra Date: Thu, 8 Nov 2018 13:01:55 +0530 Subject: [PATCH] More Bug fixes UI and Permissions --- .../education/doctype/student/student.json | 2 +- erpnext/education/doctype/student/student.py | 6 ++--- erpnext/public/js/education/web-academy.js | 12 ++++++--- .../components/AcademyProgramCard.vue | 27 +++++++++++++++++-- erpnext/www/academy.py | 14 ++++++---- 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/erpnext/education/doctype/student/student.json b/erpnext/education/doctype/student/student.json index 2e055bb1b1..7205273a52 100644 --- a/erpnext/education/doctype/student/student.json +++ b/erpnext/education/doctype/student/student.json @@ -1188,7 +1188,7 @@ "istable": 0, "max_attachments": 0, "menu_index": 0, - "modified": "2018-11-07 22:11:03.824250", + "modified": "2018-11-08 12:26:01.047163", "modified_by": "Administrator", "module": "Education", "name": "Student", diff --git a/erpnext/education/doctype/student/student.py b/erpnext/education/doctype/student/student.py index 69959ea784..d23e0a04e0 100644 --- a/erpnext/education/doctype/student/student.py +++ b/erpnext/education/doctype/student/student.py @@ -55,7 +55,7 @@ class Student(Document): 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']) + program_enrollments = frappe.get_all("Program Enrollment", filters={"student": self.name}, fields=['program']) if not program_enrollments: return None else: @@ -79,7 +79,7 @@ class Student(Document): "program": program_name, "enrollment_date": frappe.utils.datetime.datetime.now() }) - enrollment.save() + enrollment.save(ignore_permissions=True) enrollment.submit() frappe.db.commit() return enrollment @@ -92,7 +92,7 @@ class Student(Document): "program_enrollment": program_enrollment, "enrollment_date": enrollment_date }) - enrollment.save() + enrollment.save(ignore_permissions=True) frappe.db.commit() def get_timeline_data(doctype, name): diff --git a/erpnext/public/js/education/web-academy.js b/erpnext/public/js/education/web-academy.js index e6b48ecb28..8088a5060d 100644 --- a/erpnext/public/js/education/web-academy.js +++ b/erpnext/public/js/education/web-academy.js @@ -48,8 +48,10 @@ var store = { email: frappe.session.user } }).then( r => { - for(var ii=0; ii < r.message.length; ii++){ - this.enrolledPrograms.add(r.message[ii]) + if(r.message){ + for(var ii=0; ii < r.message.length; ii++){ + this.enrolledPrograms.add(r.message[ii]) + } } }) if (this.debug) console.log('Updated State', this.enrolledPrograms) @@ -76,8 +78,10 @@ var store = { email: frappe.session.user } }).then( r => { - for(var ii=0; ii < r.message.length; ii++){ - this.completedCourses.add(r.message[ii]) + if(r.message){ + for(var ii=0; ii < r.message.length; ii++){ + this.completedCourses.add(r.message[ii]) + } } }) if (this.debug) console.log('Updated State', this.completedCourses) diff --git a/erpnext/public/js/education/web-academy/components/AcademyProgramCard.vue b/erpnext/public/js/education/web-academy/components/AcademyProgramCard.vue index 6ddf152a49..605dec211c 100644 --- a/erpnext/public/js/education/web-academy/components/AcademyProgramCard.vue +++ b/erpnext/public/js/education/web-academy/components/AcademyProgramCard.vue @@ -10,8 +10,7 @@ @@ -37,6 +36,16 @@ export default { }) }, methods: { + primaryAction(){ + if(this.$root.$data.isLogin){ + if(this.$root.$data.checkProgramEnrollment(program_code)){ + this.$router.push('/Program/' + program.name) + } + else { + this.enroll() + } + } + } enroll() { frappe.call({ method: "erpnext.www.academy.enroll_in_program", @@ -45,6 +54,20 @@ export default { student_email_id: frappe.session.user } }) + this.$root.$data.enrolledPrograms.add(this.program_code) + this.$root.$data.updateEnrolledPrograms() + } + } + computed: { + buttonName() { + if(this.$root.$data.isLogin){ + if(this.$root.$data.checkProgramEnrollment(program_code)){ + return "Start Course" + } + else { + return "Enroll" + } + } } } }; diff --git a/erpnext/www/academy.py b/erpnext/www/academy.py index 4aec61488a..94a0a71687 100644 --- a/erpnext/www/academy.py +++ b/erpnext/www/academy.py @@ -122,9 +122,12 @@ def get_completed_courses(email=frappe.session.user): def get_continue_data(program_name): program = frappe.get_doc("Program", program_name) courses = program.get_all_children() - continue_data = get_starting_content(courses[0].course) - continue_data['course'] = courses[0].course - return continue_data + try: + continue_data = get_starting_content(courses[0].course) + continue_data['course'] = courses[0].course + return continue_data + except: + return None def create_student(student_name=frappe.session.user): student = frappe.get_doc({ @@ -132,7 +135,7 @@ def create_student(student_name=frappe.session.user): "first_name": student_name, "student_email_id": student_name, }) - student.save() + student.save(ignore_permissions=True) frappe.db.commit() return student_name @@ -157,7 +160,8 @@ def get_student_id(email=None): :param user: a user email address """ try: - return frappe.get_all('Student', filters={'student_email_id': email}, fields=['name'])[0].name + student_id = frappe.db.get_all("Student", {"student_email_id": email}, ["name"])[0].name + return student_id except IndexError: return None