feat: allow students who have already joined the course to join the cohort
Issue #271
This commit is contained in:
@@ -10,17 +10,34 @@ 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)
|
||||||
|
|
||||||
|
q = {
|
||||||
|
"doctype": "LMS Batch Membership",
|
||||||
|
"course": cohort.course,
|
||||||
|
"member": self.email,
|
||||||
|
"member_type": "Student"
|
||||||
|
}
|
||||||
|
name = frappe.db.exists(q)
|
||||||
|
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 = {
|
data = {
|
||||||
"doctype": "LMS Batch Membership",
|
"doctype": "LMS Batch Membership",
|
||||||
"course": cohort.course,
|
"course": cohort.course,
|
||||||
|
|||||||
Reference in New Issue
Block a user