feat: allow students who have already joined the course to join the cohort
Issue #271
This commit is contained in:
@@ -10,25 +10,42 @@ class CohortJoinRequest(Document):
|
|||||||
self.ensure_student()
|
self.ensure_student()
|
||||||
|
|
||||||
def ensure_student(self):
|
def ensure_student(self):
|
||||||
|
# case 1 - user is already a member
|
||||||
q = {
|
q = {
|
||||||
"doctype": "LMS Batch Membership",
|
"doctype": "LMS Batch Membership",
|
||||||
"cohort": self.cohort,
|
"cohort": self.cohort,
|
||||||
"subgroup": self.subgroup,
|
"subgroup": self.subgroup,
|
||||||
"email": self.email
|
"member": self.email,
|
||||||
|
"member_type": "Student"
|
||||||
}
|
}
|
||||||
if frappe.db.exists(q):
|
if frappe.db.exists(q):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# case 2 - user has signed up for this course, possibly not this cohort
|
||||||
cohort = frappe.get_doc("Cohort", self.cohort)
|
cohort = frappe.get_doc("Cohort", self.cohort)
|
||||||
|
|
||||||
data = {
|
q = {
|
||||||
"doctype": "LMS Batch Membership",
|
"doctype": "LMS Batch Membership",
|
||||||
"course": cohort.course,
|
"course": cohort.course,
|
||||||
"cohort": self.cohort,
|
|
||||||
"subgroup": self.subgroup,
|
|
||||||
"member": self.email,
|
"member": self.email,
|
||||||
"member_type": "Student",
|
"member_type": "Student"
|
||||||
"role": "Member"
|
|
||||||
}
|
}
|
||||||
doc = frappe.get_doc(data)
|
name = frappe.db.exists(q)
|
||||||
doc.insert(ignore_permissions=True)
|
if name:
|
||||||
|
doc = frappe.get_doc("LMS Batch Membership", name)
|
||||||
|
doc.cohort = self.cohort
|
||||||
|
doc.subgroup = self.subgroup
|
||||||
|
doc.save(ignore_permissions=True)
|
||||||
|
else:
|
||||||
|
# case 3 - user has not signed up for this course yet
|
||||||
|
data = {
|
||||||
|
"doctype": "LMS Batch Membership",
|
||||||
|
"course": cohort.course,
|
||||||
|
"cohort": self.cohort,
|
||||||
|
"subgroup": self.subgroup,
|
||||||
|
"member": self.email,
|
||||||
|
"member_type": "Student",
|
||||||
|
"role": "Member"
|
||||||
|
}
|
||||||
|
doc = frappe.get_doc(data)
|
||||||
|
doc.insert(ignore_permissions=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user