feat: added get_url method to cohort doctypes

This is required to make it easier to include links in the email
notification to mentors.

Issue #271
This commit is contained in:
Anand Chitipothu
2021-12-01 08:43:10 +05:30
parent ffd9e9d48e
commit 6c747ff8b4
3 changed files with 13 additions and 2 deletions

View File

@@ -5,6 +5,9 @@ import frappe
from frappe.model.document import Document
class Cohort(Document):
def get_url(self):
return f"{frappe.utils.get_url()}/courses/{self.course}/cohorts/{self.slug}"
def get_subgroups(self, include_counts=False):
names = frappe.get_all("Cohort Subgroup", filters={"cohort": self.name}, pluck="name")
subgroups = [frappe.get_doc("Cohort Subgroup", name) for name in names]

View File

@@ -1,8 +1,12 @@
# Copyright (c) 2021, FOSS United and contributors
# For license information, please see license.txt
# import frappe
import frappe
from frappe.model.document import Document
class CohortMentor(Document):
pass
def get_subgroup(self):
return frappe.get_doc("Cohort Subgroup", self.subgroup)
def get_user(self):
return frappe.get_doc("User", self.email)

View File

@@ -10,6 +10,10 @@ class CohortSubgroup(Document):
if not self.invite_code:
self.invite_code = random_string(8)
def get_url(self):
cohort = frappe.get_doc("Cohort", self.cohort)
return f"{frappe.utils.get_url()}/courses/{self.course}/subgroups/{cohort.slug}/{self.slug}"
def get_invite_link(self):
cohort = frappe.get_doc("Cohort", self.cohort)
return f"{frappe.utils.get_url()}/courses/{self.course}/join/{cohort.slug}/{self.slug}/{self.invite_code}"