25
school/www/cohorts/cohort.html
Normal file
25
school/www/cohorts/cohort.html
Normal file
@@ -0,0 +1,25 @@
|
||||
{% extends "www/cohorts/base.html" %}
|
||||
{% block title %}Manage {{ course.title }}{% endblock %}
|
||||
|
||||
{% block page_content %}
|
||||
<h2>{{cohort.title}} <span class="badge badge-secondary">Cohort</span></h2>
|
||||
|
||||
<h5>Subgroups</h5>
|
||||
<ul class="list-group">
|
||||
{% for sg in cohort.get_subgroups(include_counts=True) %}
|
||||
<li class="list-group-item">
|
||||
<div>
|
||||
<a class="subgroup-title" href="/courses/{{course.name}}/subgroups/{{cohort.slug}}/{{sg.slug}}">{{sg.title}}</a>
|
||||
</div>
|
||||
<div style="font-size: 0.8em;">
|
||||
{{sg.num_mentors}} Mentors
|
||||
|
|
||||
{{sg.num_students}} Students
|
||||
|
|
||||
{{sg.num_join_requests}} Join Requests
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
34
school/www/cohorts/cohort.py
Normal file
34
school/www/cohorts/cohort.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import frappe
|
||||
from . import utils
|
||||
|
||||
def get_context(context):
|
||||
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()
|
||||
cohort = course and get_cohort(course, frappe.form_dict["cohort"])
|
||||
|
||||
if not cohort:
|
||||
context.template = "www/404.html"
|
||||
return
|
||||
|
||||
utils.add_nav(context, "All Courses", "/courses")
|
||||
utils.add_nav(context, course.title, "/courses/" + course.name)
|
||||
utils.add_nav(context, "Cohorts", "/courses/" + course.name + "/cohorts")
|
||||
|
||||
context.course = course
|
||||
context.cohort = cohort
|
||||
|
||||
def get_cohort(course, cohort_slug):
|
||||
cohort = utils.get_cohort(course, cohort_slug)
|
||||
|
||||
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
|
||||
|
||||
136
school/www/cohorts/subgroup.html
Normal file
136
school/www/cohorts/subgroup.html
Normal file
@@ -0,0 +1,136 @@
|
||||
{% extends "www/cohorts/base.html" %}
|
||||
{% block title %} Subgroup {{subgroup.title}} - {{ course.title }} {% endblock %}
|
||||
|
||||
{% block page_content %}
|
||||
<h2>{{subgroup.title}} <span class="badge badge-secondary">Subgroup</span></h2>
|
||||
|
||||
<ul class="nav nav-tabs">
|
||||
{{ render_navitem("Info", "", -1, page=="info")}}
|
||||
{{ render_navitem("Students", "/students", stats.students, page=="students")}}
|
||||
{{ render_navitem("Requests to join", "/join-requests", stats.join_requests, page=="join-requests")}}
|
||||
</ul>
|
||||
<div class="my-5">
|
||||
{% if page == "info" %}
|
||||
{{ render_info() }}
|
||||
{% elif page == "students" %}
|
||||
{{ render_students() }}
|
||||
{% elif page == "join-requests" %}
|
||||
{{ render_join_requests() }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% macro render_info() %}
|
||||
<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>
|
||||
|
||||
<h5>Mentors</h5>
|
||||
{% set mentors = subgroup.get_mentors() %}
|
||||
{% if mentors %}
|
||||
{% for m in mentors %}
|
||||
<div class="my-5">
|
||||
{{ widgets.Avatar(member=m, avatar_class="avatar-small") }}
|
||||
<a href="/{{m.username}}" title="{{m.full_name}}">{{ m.full_name }}</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<em>None found.</em>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% macro render_students() %}
|
||||
{% set students = subgroup.get_students() %}
|
||||
{% if students %}
|
||||
{% for student in students %}
|
||||
<div class="my-5">
|
||||
{{ widgets.Avatar(member=student, avatar_class="avatar-small") }}
|
||||
<a href="/{{student.username}}" title="{{student.full_name}}">{{ student.full_name }}</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<em>None found.</em>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% macro render_join_requests() %}
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>When</th>
|
||||
<th>Email</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
{% for r in subgroup.get_join_requests() %}
|
||||
<tr>
|
||||
<td>{{loop.index}}</td>
|
||||
<td>{{r.creation}}</td>
|
||||
<td>{{r.email}}</td>
|
||||
<td
|
||||
data-name="{{r.name}}"
|
||||
data-email="{{r.email}}">
|
||||
<a class="action-approve" href="#">Approve</a> | <a class="action-reject" href="#">Reject</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro render_navitem(title, link, count, active) %}
|
||||
<li class="nav-item">
|
||||
<a
|
||||
class="nav-link {{ 'active' if active }}"
|
||||
href="/courses/{{course.name}}/subgroups/{{cohort.slug}}/{{subgroup.slug}}{{link}}"
|
||||
>{{title}}
|
||||
{% if count != -1 %}
|
||||
<span
|
||||
class="badge {{'badge-primary' if active else 'badge-secondary'}}"
|
||||
>{{count}}</span>
|
||||
{% endif %}
|
||||
</a>
|
||||
</li>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% block script %}
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$("#copy-to-clipboard").click(function() {
|
||||
var invite_link = $("#invite-link").text();
|
||||
navigator.clipboard.writeText(invite_link)
|
||||
.then(() => {
|
||||
$("#copy-to-clipboard").text("Copied!");
|
||||
setTimeout(
|
||||
() => $("#copy-to-clipboard").text("Copy to Clipboard"),
|
||||
500);
|
||||
});
|
||||
});
|
||||
|
||||
$(".action-approve").click(function() {
|
||||
var name = $(this).parent().data("name");
|
||||
var email = $(this).parent().data("email");
|
||||
|
||||
frappe.confirm(
|
||||
`Are you sure to accept ${email} to this subgroup?`,
|
||||
function() {
|
||||
console.log("approve", name);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$(".action-reject").click(function() {
|
||||
var name = $(this).parent().data("name");
|
||||
var email = $(this).parent().data("email");
|
||||
frappe.confirm(`Are you sure to reject <strong>${email}</strong> from joining this subgroup?`, function() {
|
||||
console.log("reject", name);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
33
school/www/cohorts/subgroup.py
Normal file
33
school/www/cohorts/subgroup.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import frappe
|
||||
from . import utils
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
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'])
|
||||
subgroup = utils.get_subgroup(cohort, frappe.form_dict['subgroup'])
|
||||
|
||||
if not subgroup:
|
||||
context.template = "www/404.html"
|
||||
return
|
||||
|
||||
utils.add_nav(context, "All Courses", "/courses")
|
||||
utils.add_nav(context, course.title, f"/courses/{course.name}")
|
||||
utils.add_nav(context, "Cohorts", f"/courses/{course.name}/cohorts")
|
||||
utils.add_nav(context, cohort.title, f"/courses/{course.name}/cohorts/{cohort.slug}")
|
||||
|
||||
context.course = course
|
||||
context.cohort = cohort
|
||||
context.subgroup = subgroup
|
||||
context.stats = get_stats(subgroup)
|
||||
context.page = frappe.form_dict["page"]
|
||||
|
||||
def get_stats(subgroup):
|
||||
return {
|
||||
"join_requests": len(subgroup.get_join_requests()),
|
||||
"students": len(subgroup.get_students())
|
||||
}
|
||||
@@ -10,6 +10,14 @@ def get_doc(doctype, name):
|
||||
except frappe.exceptions.DoesNotExistError:
|
||||
return
|
||||
|
||||
def get_cohort(course, cohort_slug):
|
||||
name = frappe.get_value("Cohort", {"course": course.name, "slug": cohort_slug})
|
||||
return name and frappe.get_doc("Cohort", name)
|
||||
|
||||
def get_subgroup(cohort, subgroup_slug):
|
||||
name = frappe.get_value("Cohort Subgroup", {"cohort": cohort.name, "slug": subgroup_slug})
|
||||
return name and frappe.get_doc("Cohort Subgroup", name)
|
||||
|
||||
def add_nav(context, title, href):
|
||||
"""Adds a breadcrumb to the navigation.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user