More Bug fixes UI and Permissions

This commit is contained in:
scmmishra 2018-11-08 13:01:55 +05:30 committed by Aditya Hase
parent 05e07b44b1
commit 8fa9adec37
5 changed files with 46 additions and 15 deletions

View File

@ -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",

View File

@ -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):

View File

@ -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)

View File

@ -10,8 +10,7 @@
</div>
<div class='card-footer text-right'>
<!-- <a class='video-btn btn btn-secondary btn-sm' data-toggle="modal" data-src=" insert jinja stuff here " data-target="#myModal">Watch Intro</a>&nbsp;&nbsp; -->
<a v-if="this.$root.$data.checkProgramEnrollment(program.name)" class='btn btn-secondary btn-sm' @click="$router.push('/Program/' + program.name)">Start Course</a>
<a v-else-if="this.$root.$data.isLogin" class='btn btn-secondary btn-sm' @click="enroll()">Enroll Now</a>
<a v-if="this.$root.$data.isLogin" class='btn btn-secondary btn-sm' @click="primaryAction()">{{ buttonName }}</a>
<a v-else class='btn btn-secondary btn-sm' href="/login#signup">Sign Up</a>
</div>
</div>
@ -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"
}
}
}
}
};

View File

@ -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