@@ -13,13 +13,26 @@
|
|||||||
| {{ stats.join_requests }} join requests
|
| {{ stats.join_requests }} join requests
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h5>Subgroups</h5>
|
{% if is_mentor %}
|
||||||
|
<div class="alert alert-info">
|
||||||
|
{% set sg = mentor.get_subgroup() %}
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<h5>All Subgroups</h5>
|
||||||
<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">
|
||||||
<div>
|
<div>
|
||||||
|
{% if is_admin %}
|
||||||
<a class="subgroup-title" href="/courses/{{course.name}}/subgroups/{{cohort.slug}}/{{sg.slug}}">{{sg.title}}</a>
|
<a class="subgroup-title" href="/courses/{{course.name}}/subgroups/{{cohort.slug}}/{{sg.slug}}">{{sg.title}}</a>
|
||||||
</div>
|
{% else %}
|
||||||
|
<span class="subgroup-title">{{sg.title}}</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
<div style="font-size: 0.8em;">
|
<div style="font-size: 0.8em;">
|
||||||
{{sg.num_mentors}} Mentors
|
{{sg.num_mentors}} Mentors
|
||||||
|
|
|
|
||||||
|
|||||||
@@ -8,27 +8,25 @@ def get_context(context):
|
|||||||
raise frappe.Redirect()
|
raise frappe.Redirect()
|
||||||
|
|
||||||
course = utils.get_course()
|
course = utils.get_course()
|
||||||
cohort = course and get_cohort(course, frappe.form_dict["cohort"])
|
cohort = course and utils.get_cohort(course, frappe.form_dict["cohort"])
|
||||||
|
|
||||||
if not cohort:
|
if not cohort:
|
||||||
context.template = "www/404.html"
|
context.template = "www/404.html"
|
||||||
return
|
return
|
||||||
|
|
||||||
|
user = frappe.session.user
|
||||||
|
mentor = cohort.get_mentor(user)
|
||||||
|
is_mentor = mentor is not None
|
||||||
|
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")
|
||||||
|
|
||||||
context.course = course
|
context.course = course
|
||||||
context.cohort = cohort
|
context.cohort = cohort
|
||||||
|
context.mentor = mentor
|
||||||
def get_cohort(course, cohort_slug):
|
context.is_mentor = is_mentor
|
||||||
cohort = utils.get_cohort(course, cohort_slug)
|
context.is_admin = is_admin
|
||||||
|
|
||||||
if cohort.is_mentor(frappe.session.user):
|
|
||||||
mentor = cohort.get_mentor(frappe.session.user)
|
|
||||||
sg = frappe.get_doc("Cohort Subgroup", mentor.subgroup)
|
|
||||||
frappe.local.flags.redirect_location = f"/courses/{course.name}/subgroups/{cohort.slug}/{sg.slug}"
|
|
||||||
raise frappe.Redirect
|
|
||||||
elif cohort.is_admin(frappe.session.user) or "System Manager" in frappe.get_roles():
|
|
||||||
return cohort
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ def get_context(context):
|
|||||||
return
|
return
|
||||||
|
|
||||||
context.cohorts = get_cohorts(context.course)
|
context.cohorts = get_cohorts(context.course)
|
||||||
|
if len(context.cohorts) == 1:
|
||||||
|
frappe.local.flags.redirect_location = context.cohorts[0].get_url()
|
||||||
|
raise frappe.Redirect
|
||||||
|
|
||||||
add_nav(context, "All Courses", "/courses")
|
add_nav(context, "All Courses", "/courses")
|
||||||
add_nav(context, context.course.title, "/courses/" + context.course.name)
|
add_nav(context, context.course.title, "/courses/" + context.course.name)
|
||||||
@@ -24,7 +27,5 @@ def get_cohorts(course):
|
|||||||
staff_roles = frappe.get_all("Cohort Staff", filters={"course": course.name}, fields=["cohort"])
|
staff_roles = frappe.get_all("Cohort Staff", filters={"course": course.name}, fields=["cohort"])
|
||||||
mentor_roles = frappe.get_all("Cohort Mentor", filters={"course": course.name}, fields=["cohort"])
|
mentor_roles = frappe.get_all("Cohort Mentor", filters={"course": course.name}, fields=["cohort"])
|
||||||
roles = staff_roles + mentor_roles
|
roles = staff_roles + mentor_roles
|
||||||
print(roles)
|
|
||||||
names = {role.cohort for role in roles}
|
names = {role.cohort for role in roles}
|
||||||
print(names)
|
|
||||||
return [frappe.get_doc("Cohort", name) for name in names]
|
return [frappe.get_doc("Cohort", name) for name in names]
|
||||||
|
|||||||
Reference in New Issue
Block a user