fix: cohorts

This commit is contained in:
Jannat Patel
2022-10-27 11:23:44 +05:30
parent cbf852828c
commit b84a955ee1
4 changed files with 70 additions and 52 deletions

View File

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

View File

@@ -1,5 +1,7 @@
{% extends "www/cohorts/base.html" %} {% extends "www/cohorts/base.html" %}
{% block title %}Manage {{ course.title }}{% endblock %} {% block title %}
{{ _("Manage") }} {{ course.title }}
{% endblock %}
{% block page_content %} {% block page_content %}
<div class="course-home-headings"> <div class="course-home-headings">
@@ -7,12 +9,10 @@
</div> </div>
<p> <p>
{% set stats = cohort.get_stats() %} {{ frappe.db.count("Cohort Subgroup", {"cohort": cohort.name}) }} {{ _("Subgroups") }}
| {{ frappe.db.count("Cohort Mentor", {"cohort": cohort.name}) }} {{ _("Mentors") }}
{{ stats.subgroups }} {{ _("Subgroups")}} | {{ frappe.db.count("LMS Batch Membership", {"cohort": cohort.name}) }} {{ _("Students") }}
| {{ stats.mentors }} {{ _("Mentors") }} | {{ frappe.db.count("Cohort Join Request", {"cohort": cohort.name}) }} {{ _("Join Requests") }}
| {{ stats.students }} {{ _("Students") }}
| {{ stats.join_requests }} {{ _("Join Requests") }}
</p> </p>
{% if is_mentor %} {% if is_mentor %}
@@ -25,19 +25,19 @@
{% endif %} {% endif %}
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
{% set num_subgroups = cohort.get_subgroups() | length %} {% set num_subgroups = cohort.get_subgroups() | length %}
{{ render_navitem("Subgroups", "", page=page, count=num_subgroups) }} {{ render_navitem("Subgroups", "", page=page, count=num_subgroups) }}
{% for p in cohort.get_pages(scope="Cohort") %} {% for p in cohort.get_pages(scope="Cohort") %}
{{ render_navitem(p.title, p.slug, page=page) }} {{ render_navitem(p.title, p.slug, page=page) }}
{% endfor %} {% endfor %}
</ul> </ul>
<div class="my-5"> <div class="my-5">
{% if not page %} {% if not page %}
{{ render_subgroups() }} {{ render_subgroups() }}
{% else %} {% else %}
{{ render_page(page) }} {{ render_page(page) }}
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}
@@ -55,7 +55,7 @@
<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>

View File

@@ -1,38 +1,53 @@
{% extends "www/cohorts/base.html" %} {% extends "www/cohorts/base.html" %}
{% block title %}Manage {{ course.title }}{% endblock %} {% block title %}
_("Manage") {{ course.title }}
{% endblock %}
{% block page_content %} {% block page_content %}
{% if cohorts %} {% if cohorts %}
<h2>{{ _("Cohorts") }}</h2> <h2>
<div class="row"> {{ _("Cohorts") }}
{% for cohort in cohorts %} </h2>
<div class="col-md-6"> <div class="row">
{{ render_cohort(course, cohort) }} {% for cohort in cohorts %}
</div> <div class="col-md-6">
{% endfor %} {{ render_cohort(course, cohort) }}
</div> </div>
{% else %} {% endfor %}
<h2>{{ _("Permission Denied") }}</h2> </div>
<p>{{ _("You don't have permission to manage this course.") }}</p> {% else %}
{% endif %} <h2>
{{ _("Permission Denied") }}
</h2>
<p>
{{ _("You don't have permission to manage this course.") }}
</p>
{% endif %}
{% endblock %} {% endblock %}
{% macro render_cohort(course, cohort) %} {% macro render_cohort(course, cohort) %}
<div class="card"> <div class="cards-parent">
<div class="card-body"> <div class="common-card-style flex-column p-5">
<h5 class="card-title">{{cohort.title}}</h5> <h5 class="card-title">
<h6 class="card-subtitle mb-2 text-muted">{{cohort.begin_date}} - {{cohort.end_date}}</h6> {{ cohort.title }}
<p> </h5>
{% set stats = cohort.get_stats() %}
{{ stats.subgroups }} Subgroups {% if cohort.begin_date %}
| {{ stats.mentors }} Mentors <h6 class="card-subtitle mb-2 text-muted">
| {{ stats.students }} students {{ frappe.utils.format_date(cohort.begin_date, "medium") }} - {{ frappe.utils.format_date(cohort.end_date, "medium") }}
| {{ stats.join_requests }} join requests </h6>
</p> {% endif %}
<a href="/courses/{{course.name}}/cohorts/{{cohort.slug}}" class="card-link">{{ _("Manage") }}</a> <p class="mb-0">
</div> {{ frappe.db.count("Cohort Subgroup", {"cohort": cohort.name}) }} {{ _("Subgroups") }}
| {{ frappe.db.count("Cohort Mentor", {"cohort": cohort.name}) }} {{ _("Mentors") }}
| {{ frappe.db.count("LMS Batch Membership", {"cohort": cohort.name}) }} {{ _("Students") }}
| {{ frappe.db.count("Cohort Join Request", {"cohort": cohort.name}) }} {{ _("Join Requests") }}
</p>
<a class="stretched-link" href="/courses/{{course.name}}/cohorts/{{cohort.slug}}"></a>
</div>
</div> </div>
{% endmacro %} {% endmacro %}

View File

@@ -292,12 +292,7 @@
{% set lesson_index = get_lesson_index(membership.current_lesson) if membership and {% set lesson_index = get_lesson_index(membership.current_lesson) if membership and
membership.current_lesson else "1.1" if first_lesson_exists(course.name) else None %} membership.current_lesson else "1.1" if first_lesson_exists(course.name) else None %}
{% if show_start_learing_cta(course, membership) %} {% if is_instructor(course.name) and not course.published and course.status != "Under Review" %}
<div class="btn btn-primary wide-button join-batch" data-course="{{ course.name | urlencode }}">
{{ _("Start Learning") }}
</div>
{% elif is_instructor(course.name) and not course.published and course.status != "Under Review" %}
<div class="btn btn-primary wide-button" id="submit-for-review" data-course="{{ course.name | urlencode }}"> <div class="btn btn-primary wide-button" id="submit-for-review" data-course="{{ course.name | urlencode }}">
{{ _("Submit for Review") }} {{ _("Submit for Review") }}
</div> </div>
@@ -323,6 +318,11 @@
href="{{ get_lesson_url(course.name, lesson_index) }}{{ course.query_parameter }}"> href="{{ get_lesson_url(course.name, lesson_index) }}{{ course.query_parameter }}">
{{ _("Continue Learning") }} {{ _("Continue Learning") }}
</a> </a>
{% elif show_start_learing_cta(course, membership) %}
<div class="btn btn-primary wide-button join-batch" data-course="{{ course.name | urlencode }}">
{{ _("Start Learning") }}
</div>
{% endif %} {% endif %}
{% set progress = frappe.utils.cint(membership.progress) %} {% set progress = frappe.utils.cint(membership.progress) %}