Merge pull request #405 from pateljannat/cohorts

This commit is contained in:
Jannat Patel
2022-10-13 20:51:46 +05:30
committed by GitHub
7 changed files with 64 additions and 62 deletions

View File

@@ -61,6 +61,7 @@
"fieldtype": "Data", "fieldtype": "Data",
"in_list_view": 1, "in_list_view": 1,
"label": "Slug", "label": "Slug",
"reqd": 1,
"unique": 1 "unique": 1
}, },
{ {
@@ -105,7 +106,7 @@
"link_fieldname": "cohort" "link_fieldname": "cohort"
} }
], ],
"modified": "2021-12-16 14:44:25.406301", "modified": "2022-10-13 15:46:32.322926",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "Cohort", "name": "Cohort",
@@ -127,5 +128,6 @@
], ],
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"states": [],
"track_changes": 1 "track_changes": 1
} }

View File

@@ -137,7 +137,7 @@ class LMSCourse(Document):
def get_cohorts(self): def get_cohorts(self):
return frappe.get_all("Cohort", {"course": self.name}, order_by="creation") return frappe.get_all("Cohort", {"course": self.name}, ["name", "slug"], order_by="creation")
def get_cohort(self, cohort_slug): def get_cohort(self, cohort_slug):

View File

@@ -2,22 +2,25 @@
{% block title %}Manage {{ course.title }}{% endblock %} {% block title %}Manage {{ course.title }}{% endblock %}
{% block page_content %} {% block page_content %}
<h2>{{cohort.title}} <span class="badge badge-secondary">Cohort</span></h2> <div class="course-home-headings">
{{ cohort.title }}
</div>
<p> <p>
{% set stats = cohort.get_stats() %} {% set stats = cohort.get_stats() %}
{{ stats.subgroups }} Subgroups {{ stats.subgroups }} {{ _("Subgroups")}}
| {{ stats.mentors }} Mentors | {{ stats.mentors }} {{ _("Mentors") }}
| {{ stats.students }} students | {{ stats.students }} {{ _("Students") }}
| {{ stats.join_requests }} join requests | {{ stats.join_requests }} {{ _("Join Requests") }}
</p> </p>
{% if is_mentor %} {% if is_mentor %}
<div class="alert alert-info"> {% set sg = mentor.get_subgroup() %}
{% set sg = mentor.get_subgroup() %} <div class="alert alert-info medium">
<p>You are a mentor of <b>{{sg.title}}</b> subgroup.</p> <a href="{{sg.get_url()}}">
<p><a href="{{sg.get_url()}}" class="btn btn-primary">Visit Your Subgroup &rarr;</a></p> {{ _("You are a mentor of {0} subgroup.").format(frappe.bold(sg.title)) }}
</a>
</div> </div>
{% endif %} {% endif %}
@@ -40,38 +43,36 @@
{% endblock %} {% endblock %}
{% macro render_subgroups() %} {% 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">
<div> <div>
<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 }}
>{{sg.title}}</a> </a>
</div> </div>
<div style="font-size: 0.8em;"> <div style="font-size: 0.8em;">
{{sg.num_mentors}} Mentors {{ sg.num_mentors }} {{ _("Mentors") }}
| |
{{sg.num_students}} Students {{sg.num_students}} {{ _(Students) }}
| |
{{sg.num_join_requests}} Join Requests {{sg.num_join_requests}} {{ _("Join Requests") }}
</div> </div>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endmacro %} {% endmacro %}
{% macro render_navitem(title, link, page, count=-1) %} {% macro render_navitem(title, link, page, count=-1) %}
<li class="nav-item"> <li class="nav-item">
<a <a class="nav-link {{ 'active' if link==page }}" href="/courses/{{course.name}}/cohorts/{{cohort.slug}}/{{link}}">
class="nav-link {{ 'active' if link==page }}" {{ title }}
href="/courses/{{course.name}}/cohorts/{{cohort.slug}}/{{link}}" {% if count != -1 %}
>{{title}} <span class="badge {{'badge-primary' if link==page else 'badge-secondary'}}">
{% if count != -1 %} {{ count }}
<span </span>
class="badge {{'badge-primary' if link==page else 'badge-secondary'}}" {% endif %}
>{{count}}</span> </a>
{% endif %} </li>
</a>
</li>
{% endmacro %} {% endmacro %}

View File

@@ -1,5 +1,6 @@
import frappe import frappe
from .utils import get_course, add_nav from .utils import get_course, add_nav
from frappe.utils import get_url
def get_context(context): def get_context(context):
context.no_cache = 1 context.no_cache = 1
@@ -14,7 +15,7 @@ def get_context(context):
context.cohorts = get_cohorts(context.course) context.cohorts = get_cohorts(context.course)
if len(context.cohorts) == 1: if len(context.cohorts) == 1:
frappe.local.flags.redirect_location = context.cohorts[0].get_url() frappe.local.flags.redirect_location = f"{get_url()}/courses/{context.course.name}/cohorts/{context.cohorts[0].slug}"
raise frappe.Redirect raise frappe.Redirect
add_nav(context, "All Courses", "/courses") add_nav(context, "All Courses", "/courses")

View File

@@ -2,10 +2,9 @@
{% block title %} Subgroup {{subgroup.title}} - {{ course.title }} {% endblock %} {% block title %} Subgroup {{subgroup.title}} - {{ course.title }} {% endblock %}
{% block page_content %} {% block page_content %}
<h2 id="page-title" <div id="page-title" class="course-home-headings" data-subgroup="{{subgroup.name}}" data-title="{{subgroup.title}}">
data-subgroup="{{subgroup.name}}" {{subgroup.title}}
data-title="{{subgroup.title}}" </div>
>{{subgroup.title}} <span class="badge badge-secondary">Subgroup</span></h2>
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
{{ render_navitem("Mentors", "/mentors", stats.mentors, page=="mentors")}} {{ render_navitem("Mentors", "/mentors", stats.mentors, page=="mentors")}}
@@ -51,31 +50,30 @@
{% endmacro %} {% endmacro %}
{% macro render_mentors() %} {% macro render_mentors() %}
<h5>Mentors</h5>
{% set mentors = subgroup.get_mentors() %} {% set mentors = subgroup.get_mentors() %}
{% if mentors %} {% if mentors %}
<div class="member-parent"> <div class="member-parent">
{% for m in mentors %} {% for m in mentors %}
{{ widgets.MemberCard(member=m, show_course_count=False) }} {{ widgets.MemberCard(member=m, avatar_class="avatar-medium", show_course_count=False) }}
{% endfor %} {% endfor %}
</div> </div>
{% else %} {% else %}
<em>None found.</em> <div>None found.</div>
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
{% macro render_students() %} {% macro render_students() %}
{% set students = subgroup.get_students() %} {% set students = subgroup.get_students() %}
{% if students %} {% if students %}
<div class="member-parent"> <div class="member-parent">
{% for student in students %} {% for student in students %}
{{ widgets.MemberCard(member=student, show_course_count=False) }} {{ widgets.MemberCard(member=student, avatar_class="avatar-medium", show_course_count=False) }}
{% endfor %} {% endfor %}
</div> </div>
{% else %} {% else %}
<em>None found.</em> <div>None found.</div>
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
@@ -110,7 +108,7 @@
{% endfor %} {% endfor %}
</table> </table>
{% else %} {% else %}
<p><em>There are no pending join requests.</em></p> <div> {{ _("There are no pending join requests.") }} </div>
{% endif %} {% endif %}
{% set rejected_requests = subgroup.get_join_requests(status="Rejected") %} {% set rejected_requests = subgroup.get_join_requests(status="Rejected") %}

View File

@@ -315,7 +315,7 @@
{% elif is_cohort_staff(course.name, frappe.session.user) %} {% elif is_cohort_staff(course.name, frappe.session.user) %}
<a class="btn btn-secondary button-links wide-button" href="/courses/{{course.name}}/manage"> <a class="btn btn-secondary button-links wide-button" href="/courses/{{course.name}}/manage">
{{ _("Manage the course") }} {{ _("Manage Cohorts") }}
</a> </a>
{% elif membership %} {% elif membership %}

View File