refactor: renamed batch and membership doctypes

This commit is contained in:
Jannat Patel
2023-08-25 14:46:11 +05:30
parent b197e36ba7
commit b8b32681bf
45 changed files with 246 additions and 275 deletions

View File

@@ -4,7 +4,7 @@ import frappe
def get_context(context):
context.no_cache = 1
batch_name = frappe.form_dict["batch"]
context.batch = frappe.get_doc("LMS Batch", batch_name)
context.batch = frappe.get_doc("LMS Batch Old", batch_name)
context.already_a_member = context.batch.is_member(frappe.session.user)
context.batch.course_title = frappe.db.get_value(
"LMS Course", context.batch.course, "title"

View File

@@ -12,7 +12,7 @@ def get_context(context):
raise frappe.PermissionError(_("You are not allowed to access this page."))
membership = frappe.db.exists(
"LMS Batch Membership", {"member": frappe.session.user, "course": course_name}
"LMS Enrollment", {"member": frappe.session.user, "course": course_name}
)
if membership:

View File

@@ -1,78 +1,69 @@
{% extends "www/cohorts/base.html" %}
{% block title %}
{{ _("Manage") }} {{ course.title }}
{% endblock %}
{% block page_content %}
<div class="course-home-headings">
{{ cohort.title }}
</div>
{% extends "www/cohorts/base.html" %} {% block title %} {{ _("Manage") }} {{
course.title }} {% endblock %} {% block page_content %}
<div class="course-home-headings">{{ cohort.title }}</div>
<p>
{{ 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") }}
{{ frappe.db.count("Cohort Subgroup", {"cohort": cohort.name}) }} {{
_("Subgroups") }} | {{ frappe.db.count("Cohort Mentor", {"cohort":
cohort.name}) }} {{ _("Mentors") }} | {{ frappe.db.count("LMS Enrollment",
{"cohort": cohort.name}) }} {{ _("Students") }} | {{ frappe.db.count("Cohort
Join Request", {"cohort": cohort.name}) }} {{ _("Join Requests") }}
</p>
{% if is_mentor %}
{% set sg = mentor.get_subgroup() %}
{% if is_mentor %} {% set sg = mentor.get_subgroup() %}
<div class="alert alert-info medium">
<a href="{{sg.get_url()}}">
{{ _("You are a mentor of {0} subgroup.").format(frappe.bold(sg.title)) }}
</a>
<a href="{{sg.get_url()}}">
{{ _("You are a mentor of {0} subgroup.").format(frappe.bold(sg.title))
}}
</a>
</div>
{% endif %}
<ul class="nav nav-tabs">
{% set num_subgroups = cohort.get_subgroups() | length %}
{{ render_navitem("Subgroups", "", page=page, count=num_subgroups) }}
{% for p in cohort.get_pages(scope="Cohort") %}
{{ render_navitem(p.title, p.slug, page=page) }}
{% endfor %}
{% set num_subgroups = cohort.get_subgroups() | length %} {{
render_navitem("Subgroups", "", page=page, count=num_subgroups) }} {% for p
in cohort.get_pages(scope="Cohort") %} {{ render_navitem(p.title, p.slug,
page=page) }} {% endfor %}
</ul>
<div class="my-5">
{% if not page %}
{{ render_subgroups() }}
{% else %}
{{ render_page(page) }}
{% endif %}
{% if not page %} {{ render_subgroups() }} {% else %} {{ render_page(page)
}} {% endif %}
</div>
{% endblock %}
{% macro render_subgroups() %}
<ul class="list-group">
{% for sg in cohort.get_subgroups(include_counts=True) %}
<li class="list-group-item">
<div>
<a class="subgroup-title" style="font-weight: 700; color: inherit;"
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>
{% endmacro %}
{% macro render_navitem(title, link, page, count=-1) %}
<li class="nav-item">
<a class="nav-link {{ 'active' if link==page }}" href="/courses/{{course.name}}/cohorts/{{cohort.slug}}/{{link}}">
{{ title }}
{% if count != -1 %}
<span class="badge {{'badge-primary' if link==page else 'badge-secondary'}}">
{{ count }}
</span>
{% endif %}
</a>
</li>
{% endblock %} {% macro render_subgroups() %}
<ul class="list-group">
{% for sg in cohort.get_subgroups(include_counts=True) %}
<li class="list-group-item">
<div>
<a
class="subgroup-title"
style="font-weight: 700; color: inherit"
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>
{% endmacro %} {% macro render_navitem(title, link, page, count=-1) %}
<li class="nav-item">
<a
class="nav-link {{ 'active' if link==page }}"
href="/courses/{{course.name}}/cohorts/{{cohort.slug}}/{{link}}"
>
{{ title }} {% if count != -1 %}
<span
class="badge {{'badge-primary' if link==page else 'badge-secondary'}}"
>
{{ count }}
</span>
{% endif %}
</a>
</li>
{% endmacro %}

View File

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

View File

@@ -56,7 +56,7 @@ def get_courses():
live_courses, upcoming_courses = [], []
for course in courses:
course.enrollment_count = frappe.db.count(
"LMS Batch Membership", {"course": course.name, "member_type": "Student"}
"LMS Enrollment", {"course": course.name, "member_type": "Student"}
)
course.avg_rating = get_average_rating(course.name) or 0
if course.upcoming: