From 037e946bbe524fdbed31d921276ebbfd70eec226 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Wed, 4 Aug 2021 19:07:14 +0530 Subject: [PATCH] fix: mentors cleanup --- .../lms_batch_membership.json | 9 ++-- .../lms/doctype/lms_course/lms_course.py | 22 ++------ community/lms/widgets/RenderBatch.html | 30 ----------- community/www/batch/utils.py | 3 -- community/www/courses/course.html | 52 ------------------- 5 files changed, 10 insertions(+), 106 deletions(-) delete mode 100644 community/lms/widgets/RenderBatch.html diff --git a/community/lms/doctype/lms_batch_membership/lms_batch_membership.json b/community/lms/doctype/lms_batch_membership/lms_batch_membership.json index f7f1f2dc..3a0bfa0c 100644 --- a/community/lms/doctype/lms_batch_membership/lms_batch_membership.json +++ b/community/lms/doctype/lms_batch_membership/lms_batch_membership.json @@ -37,6 +37,7 @@ "fieldname": "member_type", "fieldtype": "Select", "in_list_view": 1, + "in_standard_filter": 1, "label": "Member Type", "options": "\nStudent\nMentor\nStaff" }, @@ -44,7 +45,6 @@ "default": "Member", "fieldname": "role", "fieldtype": "Select", - "in_standard_filter": 1, "label": "Role", "options": "\nMember\nAdmin" }, @@ -63,9 +63,10 @@ { "fetch_from": "batch.course", "fieldname": "course", - "fieldtype": "Data", + "fieldtype": "Link", "in_list_view": 1, - "label": "Course" + "label": "Course", + "options": "LMS Course" }, { "fieldname": "current_lesson", @@ -83,7 +84,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-07-06 20:50:46.885325", + "modified": "2021-08-04 17:10:42.708479", "modified_by": "Administrator", "module": "LMS", "name": "LMS Batch Membership", diff --git a/community/lms/doctype/lms_course/lms_course.py b/community/lms/doctype/lms_course/lms_course.py index 5ec7a17f..867dda3b 100644 --- a/community/lms/doctype/lms_course/lms_course.py +++ b/community/lms/doctype/lms_course/lms_course.py @@ -74,8 +74,11 @@ class LMSCourse(Document): mentors = frappe.get_all("LMS Course Mentor Mapping", {"course": self.name}, ["mentor"]) for mentor in mentors: member = frappe.get_doc("User", mentor.mentor) - # TODO: change this to count query - member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"})) + member.batch_count = frappe.db.count("LMS Batch Membership", + { + "member": member.name, + "member_type": "Mentor" + }) course_mentors.append(member) return course_mentors @@ -238,21 +241,6 @@ class LMSCourse(Document): membership.batch_title = frappe.db.get_value("LMS Batch", membership.batch, "title") return all_memberships - def get_mentors(self, batch=None): - filters = { - "course": self.name, - "member_type": "Mentor" - } - if batch: - filters["batch"] = batch - - memberships = frappe.get_all( - "LMS Batch Membership", - filters, - ["member"]) - member_names = [m['member'] for m in memberships] - return find_all("User", name=["IN", member_names]) - def get_students(self, batch=None): """Returns (email, full_name, username) of all the students of this batch as a list of dict. """ diff --git a/community/lms/widgets/RenderBatch.html b/community/lms/widgets/RenderBatch.html deleted file mode 100644 index bb70c2c5..00000000 --- a/community/lms/widgets/RenderBatch.html +++ /dev/null @@ -1,30 +0,0 @@ -
-
-
Session every {{batch.sessions_on}}
-
{{frappe.utils.format_time(batch.start_time, "short")}} - - {{frappe.utils.format_time(batch.end_time, "short")}} -
-
Starting {{frappe.utils.format_date(batch.start_date, "medium")}}
-
mentors
- - {% for m in course.get_mentors(batch.name) %} -
- {{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }} - {{m.full_name}} -
- {% endfor %} -
- {% if can_manage or can_join %} -
-
- {% if can_manage %} - Manage - {% elif can_join %} - - {% endif %} -
-
- {% endif %} -
diff --git a/community/www/batch/utils.py b/community/www/batch/utils.py index b0e78da1..9c833602 100644 --- a/community/www/batch/utils.py +++ b/community/www/batch/utils.py @@ -24,9 +24,6 @@ def get_common_context(context): if batch: context.batch = batch - context.members = course.get_mentors(membership.batch) + course.get_students(membership.batch) - context.member_count = len(context.members) - context.course.query_parameter = "?batch=" + membership.batch if membership and membership.batch else "" context.livecode_url = get_livecode_url() diff --git a/community/www/courses/course.html b/community/www/courses/course.html index 3046c8ae..0982e1ed 100644 --- a/community/www/courses/course.html +++ b/community/www/courses/course.html @@ -196,55 +196,3 @@ {% endif %} {% endmacro %} - -{% macro BatchSection(course) %} -
-
- {% if course.is_mentor(frappe.session.user) %} - {{ BatchSectionForMentors(course, course.get_batches(mentor=frappe.session.user)) }} - {% else %} - {{ BatchSectionForStudents(course, course.get_upcoming_batches()) }} - {% endif %} -
-
-{% endmacro %} -{% macro BatchSectionForMentors(course, mentor_batches) %} -

Your Batches

- -{% if mentor_batches %} - -
- {% for batch in mentor_batches %} -
- {{ widgets.RenderBatch(course=course, batch=batch, can_manage=True) }} -
- {% endfor %} -
- -Add a new batch -{% else %} -
-

- You are a mentor for this course. -

- Create your first batch -
-{% endif %} -{% endmacro %} - -{% macro BatchSectionForStudents(course, upcoming_batches) %} -{% if upcoming_batches %} -
-

Upcoming Batches

-
- {% for batch in upcoming_batches %} -
- {{ widgets.RenderBatch(course=course, batch=batch, can_join=True) }} -
- {% endfor %} -
- {% else %} -
There are no Upcoming Batches for this course currently.
- {% endif %} -
-{% endmacro %}