From cd0cc2b5011d0f955437c6e3a532241370401945 Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Sun, 5 Dec 2021 00:13:05 +0530 Subject: [PATCH] feat: added support to get subgroups in sorted order Issue #271 --- school/lms/doctype/cohort/cohort.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/school/lms/doctype/cohort/cohort.py b/school/lms/doctype/cohort/cohort.py index 30c0983f..c0d9a191 100644 --- a/school/lms/doctype/cohort/cohort.py +++ b/school/lms/doctype/cohort/cohort.py @@ -8,7 +8,7 @@ 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): + def get_subgroups(self, include_counts=False, sort_by=None): names = frappe.get_all("Cohort Subgroup", filters={"cohort": self.name}, pluck="name") subgroups = [frappe.get_doc("Cohort Subgroup", name) for name in names] subgroups = sorted(subgroups, key=lambda sg: sg.title) @@ -21,6 +21,9 @@ class Cohort(Document): s.num_mentors = mentors.get(s.name, 0) s.num_students = students.get(s.name, 0) s.num_join_requests = join_requests.get(s.name, 0) + + if sort_by: + subgroups.sort(key=lambda sg: getattr(sg, sort_by), reverse=True) return subgroups def _get_subgroup_counts(self, doctype, **kw):