feat: added support for custom web pages for cohorts
This allows adding custom web pages to each cohort by defining a web template and attaching it to the cohort. Issue #271
This commit is contained in:
@@ -143,6 +143,7 @@ website_route_rules = [
|
|||||||
{"from_route": "/courses/<course>/join", "to_route": "batch/join"},
|
{"from_route": "/courses/<course>/join", "to_route": "batch/join"},
|
||||||
{"from_route": "/courses/<course>/manage", "to_route": "cohorts"},
|
{"from_route": "/courses/<course>/manage", "to_route": "cohorts"},
|
||||||
{"from_route": "/courses/<course>/cohorts/<cohort>", "to_route": "cohorts/cohort"},
|
{"from_route": "/courses/<course>/cohorts/<cohort>", "to_route": "cohorts/cohort"},
|
||||||
|
{"from_route": "/courses/<course>/cohorts/<cohort>/<page>", "to_route": "cohorts/cohort"},
|
||||||
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>", "to_route": "cohorts/subgroup", "defaults": {"page": "info"}},
|
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>", "to_route": "cohorts/subgroup", "defaults": {"page": "info"}},
|
||||||
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/students", "to_route": "cohorts/subgroup", "defaults": {"page": "students"}},
|
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/students", "to_route": "cohorts/subgroup", "defaults": {"page": "students"}},
|
||||||
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/join-requests", "to_route": "cohorts/subgroup", "defaults": {"page": "join-requests"}},
|
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/join-requests", "to_route": "cohorts/subgroup", "defaults": {"page": "join-requests"}},
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
"end_date",
|
"end_date",
|
||||||
"duration",
|
"duration",
|
||||||
"section_break_8",
|
"section_break_8",
|
||||||
"description"
|
"description",
|
||||||
|
"pages"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -89,6 +90,12 @@
|
|||||||
"label": "Course",
|
"label": "Course",
|
||||||
"options": "LMS Course",
|
"options": "LMS Course",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "pages",
|
||||||
|
"fieldtype": "Table",
|
||||||
|
"label": "Pages",
|
||||||
|
"options": "Cohort Web Page"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
@@ -109,7 +116,7 @@
|
|||||||
"link_fieldname": "cohort"
|
"link_fieldname": "cohort"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2021-11-29 15:13:41.296384",
|
"modified": "2021-12-04 23:22:10.248781",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Cohort",
|
"name": "Cohort",
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ class Cohort(Document):
|
|||||||
filters = {"cohort": self.name, **kw}
|
filters = {"cohort": self.name, **kw}
|
||||||
return frappe.db.count(doctype, filters=filters)
|
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):
|
def get_stats(self):
|
||||||
return {
|
return {
|
||||||
"subgroups": self._get_count("Cohort Subgroup"),
|
"subgroups": self._get_count("Cohort Subgroup"),
|
||||||
|
|||||||
0
school/lms/doctype/cohort_web_page/__init__.py
Normal file
0
school/lms/doctype/cohort_web_page/__init__.py
Normal file
64
school/lms/doctype/cohort_web_page/cohort_web_page.json
Normal file
64
school/lms/doctype/cohort_web_page/cohort_web_page.json
Normal file
@@ -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"
|
||||||
|
}
|
||||||
9
school/lms/doctype/cohort_web_page/cohort_web_page.py
Normal file
9
school/lms/doctype/cohort_web_page/cohort_web_page.py
Normal file
@@ -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
|
||||||
@@ -19,10 +19,26 @@
|
|||||||
<p>You are a mentor of <b>{{sg.title}}</b> subgroup.</p>
|
<p>You are a mentor of <b>{{sg.title}}</b> subgroup.</p>
|
||||||
<p><a href="{{sg.get_url()}}" class="btn btn-primary">Visit Your Subgroup →</a></p>
|
<p><a href="{{sg.get_url()}}" class="btn btn-primary">Visit Your Subgroup →</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<h5>All Subgroups</h5>
|
<ul class="nav nav-tabs">
|
||||||
|
{{ render_navitem("Subgroups", "", page=page)}}
|
||||||
|
{% for p in cohort.pages %}
|
||||||
|
{{ render_navitem(p.title, p.slug, page=page) }}
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="my-5">
|
||||||
|
{% if not page %}
|
||||||
|
{{ render_subgroups() }}
|
||||||
|
{% else %}
|
||||||
|
{{ cohort.get_page_template(page) }}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% macro render_subgroups() %}
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
{% for sg in cohort.get_subgroups(include_counts=True) %}
|
{% for sg in cohort.get_subgroups(include_counts=True) %}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
@@ -43,5 +59,19 @@
|
|||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro render_navitem(title, link, page, count=-1) %}
|
||||||
|
<li class="nav-item">
|
||||||
|
<a
|
||||||
|
class="nav-link {{ 'active' if link==page }}"
|
||||||
|
href="/courses/{{course.name}}/cohorts/{{cohort.slug}}/{{link}}"
|
||||||
|
>{{title}}
|
||||||
|
{% if count != -1 %}
|
||||||
|
<span
|
||||||
|
class="badge {{'badge-primary' if active else 'badge-secondary'}}"
|
||||||
|
>{{count}}</span>
|
||||||
|
{% endif %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endmacro %}
|
||||||
|
|||||||
@@ -30,3 +30,4 @@ def get_context(context):
|
|||||||
context.mentor = mentor
|
context.mentor = mentor
|
||||||
context.is_mentor = is_mentor
|
context.is_mentor = is_mentor
|
||||||
context.is_admin = is_admin
|
context.is_admin = is_admin
|
||||||
|
context.page = frappe.form_dict.get("page") or ""
|
||||||
|
|||||||
Reference in New Issue
Block a user