diff --git a/school/hooks.py b/school/hooks.py index 7c217970..d73c18cf 100644 --- a/school/hooks.py +++ b/school/hooks.py @@ -143,6 +143,7 @@ website_route_rules = [ {"from_route": "/courses//join", "to_route": "batch/join"}, {"from_route": "/courses//manage", "to_route": "cohorts"}, {"from_route": "/courses//cohorts/", "to_route": "cohorts/cohort"}, + {"from_route": "/courses//cohorts//", "to_route": "cohorts/cohort"}, {"from_route": "/courses//subgroups//", "to_route": "cohorts/subgroup", "defaults": {"page": "info"}}, {"from_route": "/courses//subgroups///students", "to_route": "cohorts/subgroup", "defaults": {"page": "students"}}, {"from_route": "/courses//subgroups///join-requests", "to_route": "cohorts/subgroup", "defaults": {"page": "join-requests"}}, diff --git a/school/lms/doctype/cohort/cohort.json b/school/lms/doctype/cohort/cohort.json index 6c98c101..f9cb7527 100644 --- a/school/lms/doctype/cohort/cohort.json +++ b/school/lms/doctype/cohort/cohort.json @@ -18,7 +18,8 @@ "end_date", "duration", "section_break_8", - "description" + "description", + "pages" ], "fields": [ { @@ -89,6 +90,12 @@ "label": "Course", "options": "LMS Course", "reqd": 1 + }, + { + "fieldname": "pages", + "fieldtype": "Table", + "label": "Pages", + "options": "Cohort Web Page" } ], "index_web_pages_for_search": 1, @@ -109,7 +116,7 @@ "link_fieldname": "cohort" } ], - "modified": "2021-11-29 15:13:41.296384", + "modified": "2021-12-04 23:22:10.248781", "modified_by": "Administrator", "module": "LMS", "name": "Cohort", diff --git a/school/lms/doctype/cohort/cohort.py b/school/lms/doctype/cohort/cohort.py index a2b2df08..30c0983f 100644 --- a/school/lms/doctype/cohort/cohort.py +++ b/school/lms/doctype/cohort/cohort.py @@ -34,6 +34,11 @@ class Cohort(Document): filters = {"cohort": self.name, **kw} return frappe.db.count(doctype, filters=filters) + def get_page_template(self, slug): + for p in self.pages: + if p.slug == slug: + return p.get_template_html() + def get_stats(self): return { "subgroups": self._get_count("Cohort Subgroup"), diff --git a/school/lms/doctype/cohort_web_page/__init__.py b/school/lms/doctype/cohort_web_page/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/school/lms/doctype/cohort_web_page/cohort_web_page.json b/school/lms/doctype/cohort_web_page/cohort_web_page.json new file mode 100644 index 00000000..fac05f0e --- /dev/null +++ b/school/lms/doctype/cohort_web_page/cohort_web_page.json @@ -0,0 +1,64 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2021-12-04 23:28:40.429867", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "slug", + "title", + "template", + "scope", + "required_role" + ], + "fields": [ + { + "fieldname": "title", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Title", + "reqd": 1 + }, + { + "fieldname": "template", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Template", + "options": "Web Template", + "reqd": 1 + }, + { + "default": "Cohort", + "fieldname": "scope", + "fieldtype": "Select", + "label": "Scope", + "options": "Cohort\nSubgroup" + }, + { + "default": "Public", + "fieldname": "required_role", + "fieldtype": "Select", + "label": "Required Role", + "options": "Public\nStudent\nMentor\nAdmin" + }, + { + "fieldname": "slug", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Slug", + "reqd": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-12-04 23:33:03.954128", + "modified_by": "Administrator", + "module": "LMS", + "name": "Cohort Web Page", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/school/lms/doctype/cohort_web_page/cohort_web_page.py b/school/lms/doctype/cohort_web_page/cohort_web_page.py new file mode 100644 index 00000000..b290954e --- /dev/null +++ b/school/lms/doctype/cohort_web_page/cohort_web_page.py @@ -0,0 +1,9 @@ +# Copyright (c) 2021, Frappe and contributors +# For license information, please see license.txt + +import frappe +from frappe.model.document import Document + +class CohortWebPage(Document): + def get_template_html(self): + return frappe.get_doc("Web Template", self.template).template diff --git a/school/www/cohorts/cohort.html b/school/www/cohorts/cohort.html index 07fc9193..edfa2434 100644 --- a/school/www/cohorts/cohort.html +++ b/school/www/cohorts/cohort.html @@ -19,10 +19,26 @@

You are a mentor of {{sg.title}} subgroup.

Visit Your Subgroup →

- {% endif %} -
All Subgroups
+ + +
+{% if not page %} + {{ render_subgroups() }} +{% else %} + {{ cohort.get_page_template(page) }} +{% endif %} +
+ +{% endblock %} + +{% macro render_subgroups() %}
    {% for sg in cohort.get_subgroups(include_counts=True) %}
  • @@ -43,5 +59,19 @@
  • {% endfor %}
-{% endblock %} +{% endmacro %} +{% macro render_navitem(title, link, page, count=-1) %} + +{% endmacro %} diff --git a/school/www/cohorts/cohort.py b/school/www/cohorts/cohort.py index c6d5cf57..dae645f3 100644 --- a/school/www/cohorts/cohort.py +++ b/school/www/cohorts/cohort.py @@ -30,3 +30,4 @@ def get_context(context): context.mentor = mentor context.is_mentor = is_mentor context.is_admin = is_admin + context.page = frappe.form_dict.get("page") or ""