feat: made all the cohort pages public
There is some info on the page that is only accessible to mentors and admins and not shown to other users.
This commit is contained in:
@@ -144,9 +144,8 @@ website_route_rules = [
|
|||||||
{"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>/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"},
|
||||||
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/students", "to_route": "cohorts/subgroup", "defaults": {"page": "students"}},
|
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/<page>", "to_route": "cohorts/subgroup"},
|
||||||
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/join-requests", "to_route": "cohorts/subgroup", "defaults": {"page": "join-requests"}},
|
|
||||||
{"from_route": "/courses/<course>/join/<cohort>/<subgroup>/<invite_code>", "to_route": "cohorts/join"},
|
{"from_route": "/courses/<course>/join/<cohort>/<subgroup>/<invite_code>", "to_route": "cohorts/join"},
|
||||||
{"from_route": "/users", "to_route": "profiles/profile"}
|
{"from_route": "/users", "to_route": "profiles/profile"}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Cohort(Document):
|
|||||||
|
|
||||||
def get_subgroups(self, include_counts=False, sort_by=None):
|
def get_subgroups(self, include_counts=False, sort_by=None):
|
||||||
names = frappe.get_all("Cohort Subgroup", filters={"cohort": self.name}, pluck="name")
|
names = frappe.get_all("Cohort Subgroup", filters={"cohort": self.name}, pluck="name")
|
||||||
subgroups = [frappe.get_doc("Cohort Subgroup", name) for name in names]
|
subgroups = [frappe.get_cached_doc("Cohort Subgroup", name) for name in names]
|
||||||
subgroups = sorted(subgroups, key=lambda sg: sg.title)
|
subgroups = sorted(subgroups, key=lambda sg: sg.title)
|
||||||
|
|
||||||
if include_counts:
|
if include_counts:
|
||||||
|
|||||||
@@ -22,7 +22,8 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
{{ render_navitem("Subgroups", "", page=page)}}
|
{% set num_subgroups = cohort.get_subgroups() | length %}
|
||||||
|
{{ render_navitem("Subgroups", "", page=page, count=num_subgroups) }}
|
||||||
{% for p in cohort.pages %}
|
{% for p in cohort.pages %}
|
||||||
{{ render_navitem(p.title, p.slug, page=page) }}
|
{{ render_navitem(p.title, p.slug, page=page) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -43,14 +44,10 @@
|
|||||||
{% 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">
|
||||||
<div>
|
<div>
|
||||||
{% if is_admin %}
|
|
||||||
<a class="subgroup-title"
|
<a class="subgroup-title"
|
||||||
style="font-weight: 700; color: inherit;"
|
style="font-weight: 700; color: inherit;"
|
||||||
href="/courses/{{course.name}}/subgroups/{{cohort.slug}}/{{sg.slug}}"
|
href="/courses/{{course.name}}/subgroups/{{cohort.slug}}/{{sg.slug}}"
|
||||||
>{{sg.title}}</a>
|
>{{sg.title}}</a>
|
||||||
{% else %}
|
|
||||||
<span class="subgroup-title">{{sg.title}}</span>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
<div style="font-size: 0.8em;">
|
<div style="font-size: 0.8em;">
|
||||||
{{sg.num_mentors}} Mentors
|
{{sg.num_mentors}} Mentors
|
||||||
@@ -72,7 +69,7 @@
|
|||||||
>{{title}}
|
>{{title}}
|
||||||
{% if count != -1 %}
|
{% if count != -1 %}
|
||||||
<span
|
<span
|
||||||
class="badge {{'badge-primary' if active else 'badge-secondary'}}"
|
class="badge {{'badge-primary' if link==page else 'badge-secondary'}}"
|
||||||
>{{count}}</span>
|
>{{count}}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ from . import utils
|
|||||||
|
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
context.no_cache = 1
|
context.no_cache = 1
|
||||||
if frappe.session.user == "Guest":
|
|
||||||
frappe.local.flags.redirect_location = "/login?redirect-to=" + frappe.request.path
|
|
||||||
raise frappe.Redirect()
|
|
||||||
|
|
||||||
course = utils.get_course()
|
course = utils.get_course()
|
||||||
cohort = course and utils.get_cohort(course, frappe.form_dict["cohort"])
|
cohort = course and utils.get_cohort(course, frappe.form_dict["cohort"])
|
||||||
if not cohort:
|
if not cohort:
|
||||||
@@ -18,9 +14,6 @@ def get_context(context):
|
|||||||
is_mentor = mentor is not None
|
is_mentor = mentor is not None
|
||||||
is_admin = cohort.is_admin(user) or "System Manager" in frappe.get_roles()
|
is_admin = cohort.is_admin(user) or "System Manager" in frappe.get_roles()
|
||||||
|
|
||||||
if not is_admin and not is_mentor :
|
|
||||||
frappe.throw("Permission Deined", frappe.PermissionError)
|
|
||||||
|
|
||||||
utils.add_nav(context, "All Courses", "/courses")
|
utils.add_nav(context, "All Courses", "/courses")
|
||||||
utils.add_nav(context, course.title, "/courses/" + course.name)
|
utils.add_nav(context, course.title, "/courses/" + course.name)
|
||||||
utils.add_nav(context, "Cohorts", "/courses/" + course.name + "/manage")
|
utils.add_nav(context, "Cohorts", "/courses/" + course.name + "/manage")
|
||||||
|
|||||||
@@ -5,29 +5,31 @@
|
|||||||
<h2>{{subgroup.title}} <span class="badge badge-secondary">Subgroup</span></h2>
|
<h2>{{subgroup.title}} <span class="badge badge-secondary">Subgroup</span></h2>
|
||||||
|
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
{{ render_navitem("Info", "", -1, page=="info")}}
|
{{ render_navitem("Mentors", "/mentors", stats.mentors, page=="mentors")}}
|
||||||
{{ render_navitem("Students", "/students", stats.students, page=="students")}}
|
{{ render_navitem("Students", "/students", stats.students, page=="students")}}
|
||||||
{{ render_navitem("Requests to join", "/join-requests", stats.join_requests, page=="join-requests")}}
|
{% if is_admin %}
|
||||||
|
{{ render_navitem("Admin", "/admin", stats.join_requests, page=="admin")}}
|
||||||
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
<div class="my-5">
|
<div class="my-5">
|
||||||
{% if page == "info" %}
|
{% if page == "info" %}
|
||||||
{{ render_info() }}
|
{{ render_info() }}
|
||||||
|
{% elif page == "mentors" %}
|
||||||
|
{{ render_mentors() }}
|
||||||
{% elif page == "students" %}
|
{% elif page == "students" %}
|
||||||
{{ render_students() }}
|
{{ render_students() }}
|
||||||
{% elif page == "join-requests" %}
|
{% elif page == "admin" %}
|
||||||
{{ render_join_requests() }}
|
{{ render_join_requests() }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% macro render_info() %}
|
{% macro render_info() %}
|
||||||
<h5>Invite Link</h5>
|
{% if is_admin %}
|
||||||
{% set link = subgroup.get_invite_link() %}
|
{% endif %}
|
||||||
<p><a href="{{ link }}" id="invite-link">{{link}}</a>
|
{% endmacro %}
|
||||||
<br>
|
|
||||||
<a class="btn btn-seconday btn-sm" id="copy-to-clipboard">Copy to Clipboard</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
|
{% macro render_mentors() %}
|
||||||
<h5>Mentors</h5>
|
<h5>Mentors</h5>
|
||||||
{% set mentors = subgroup.get_mentors() %}
|
{% set mentors = subgroup.get_mentors() %}
|
||||||
{% if mentors %}
|
{% if mentors %}
|
||||||
@@ -57,6 +59,13 @@
|
|||||||
|
|
||||||
|
|
||||||
{% macro render_join_requests() %}
|
{% macro render_join_requests() %}
|
||||||
|
<h5>Invite Link</h5>
|
||||||
|
{% set link = subgroup.get_invite_link() %}
|
||||||
|
<p><a href="{{ link }}" id="invite-link">{{link}}</a>
|
||||||
|
<br>
|
||||||
|
<a class="btn btn-seconday btn-sm" id="copy-to-clipboard">Copy to Clipboard</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
{% set join_requests = subgroup.get_join_requests() %}
|
{% set join_requests = subgroup.get_join_requests() %}
|
||||||
<h5>Pending Requests</h5>
|
<h5>Pending Requests</h5>
|
||||||
{% if join_requests %}
|
{% if join_requests %}
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ from . import utils
|
|||||||
def get_context(context):
|
def get_context(context):
|
||||||
context.no_cache = 1
|
context.no_cache = 1
|
||||||
course = utils.get_course()
|
course = utils.get_course()
|
||||||
if frappe.session.user == "Guest":
|
|
||||||
frappe.local.flags.redirect_location = "/login?redirect-to=" + frappe.request.path
|
|
||||||
raise frappe.Redirect()
|
|
||||||
|
|
||||||
cohort = utils.get_cohort(course, frappe.form_dict['cohort'])
|
cohort = utils.get_cohort(course, frappe.form_dict['cohort'])
|
||||||
subgroup = utils.get_subgroup(cohort, frappe.form_dict['subgroup'])
|
subgroup = utils.get_subgroup(cohort, frappe.form_dict['subgroup'])
|
||||||
@@ -15,6 +12,13 @@ def get_context(context):
|
|||||||
context.template = "www/404.html"
|
context.template = "www/404.html"
|
||||||
return
|
return
|
||||||
|
|
||||||
|
page = frappe.form_dict.get("page")
|
||||||
|
is_admin = subgroup.is_manager(frappe.session.user) or "System Manager" in frappe.get_roles()
|
||||||
|
|
||||||
|
if page not in ["mentors", "students", "admin"] or (page == "admin" and not is_admin):
|
||||||
|
frappe.local.flags.redirect_location = subgroup.get_url() + "/mentors"
|
||||||
|
raise frappe.Redirect
|
||||||
|
|
||||||
utils.add_nav(context, "All Courses", "/courses")
|
utils.add_nav(context, "All Courses", "/courses")
|
||||||
utils.add_nav(context, course.title, f"/courses/{course.name}")
|
utils.add_nav(context, course.title, f"/courses/{course.name}")
|
||||||
utils.add_nav(context, "Cohorts", f"/courses/{course.name}/manage")
|
utils.add_nav(context, "Cohorts", f"/courses/{course.name}/manage")
|
||||||
@@ -24,10 +28,12 @@ def get_context(context):
|
|||||||
context.cohort = cohort
|
context.cohort = cohort
|
||||||
context.subgroup = subgroup
|
context.subgroup = subgroup
|
||||||
context.stats = get_stats(subgroup)
|
context.stats = get_stats(subgroup)
|
||||||
context.page = frappe.form_dict["page"]
|
context.page = page
|
||||||
|
context.is_admin = is_admin
|
||||||
|
|
||||||
def get_stats(subgroup):
|
def get_stats(subgroup):
|
||||||
return {
|
return {
|
||||||
"join_requests": len(subgroup.get_join_requests()),
|
"join_requests": len(subgroup.get_join_requests()),
|
||||||
"students": len(subgroup.get_students())
|
"students": len(subgroup.get_students()),
|
||||||
|
"mentors": len(subgroup.get_mentors())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user