From 761f36519e4dfe741b3bf324c909eb2ac21b9c9f Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Thu, 6 May 2021 06:48:37 +0530 Subject: [PATCH] refactor: refactored the about page --- .../lms/doctype/lms_batch/lms_batch.json | 14 +++++--- community/lms/doctype/lms_batch/lms_batch.py | 15 +++++--- .../lms/doctype/lms_course/lms_course.py | 3 ++ community/www/courses/about/index.html | 35 ++++++++++++------- community/www/courses/about/index.py | 30 ++++++++-------- 5 files changed, 61 insertions(+), 36 deletions(-) diff --git a/community/lms/doctype/lms_batch/lms_batch.json b/community/lms/doctype/lms_batch/lms_batch.json index 8f0b94f0..6eb5056e 100644 --- a/community/lms/doctype/lms_batch/lms_batch.json +++ b/community/lms/doctype/lms_batch/lms_batch.json @@ -1,6 +1,5 @@ { "actions": [], - "autoname": "field:title", "creation": "2021-03-18 19:37:34.614796", "doctype": "DocType", "editable_grid": 1, @@ -51,10 +50,12 @@ "label": "Description" }, { + "default": "Public", "fieldname": "visibility", "fieldtype": "Select", + "in_list_view": 1, "label": "Visibility", - "options": "\nPublic\nUnlisted\nPrivate" + "options": "Public\nUnlisted\nPrivate" }, { "fieldname": "membership", @@ -63,16 +64,19 @@ "options": "\nOpen\nRestricted\nInvite Only\nClosed" }, { + "default": "Active", "fieldname": "status", "fieldtype": "Select", + "in_list_view": 1, "label": "Status", - "options": "\nActive\nInactive" + "options": "Active\nInactive" }, { + "default": "Ready", "fieldname": "stage", "fieldtype": "Select", "label": "Stage", - "options": "\nReady\nIn Progress\nCompleted\nCancelled" + "options": "Ready\nIn Progress\nCompleted\nCancelled" }, { "fieldname": "column_break_3", @@ -122,7 +126,7 @@ "link_fieldname": "batch" } ], - "modified": "2021-04-30 09:52:18.941276", + "modified": "2021-05-06 05:46:38.469120", "modified_by": "Administrator", "module": "LMS", "name": "LMS Batch", diff --git a/community/lms/doctype/lms_batch/lms_batch.py b/community/lms/doctype/lms_batch/lms_batch.py index 7fc547f3..9e4d5fe3 100644 --- a/community/lms/doctype/lms_batch/lms_batch.py +++ b/community/lms/doctype/lms_batch/lms_batch.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from community.www.courses.utils import get_member_with_email +from community.query import find, find_all class LMSBatch(Document): def validate(self): @@ -23,10 +24,16 @@ class LMSBatch(Document): "LMS Batch Membership", {"batch": self.name, "member_type": "Mentor"}, ["member"]) - for membership in memberships: - member = frappe.db.get_value("Community Member", membership.member, ["full_name", "photo", "abbr"], as_dict=1) - mentors.append(member) - return mentors + member_names = [m['member'] for m in memberships] + return find_all("Community Member", name=["IN", member_names]) + + def is_member(self, email): + """Checks if a person is part of a batch. + """ + member = find("Community Member", email=email) + return member and frappe.db.exists( + "LMS Batch Membership", + {"batch": self.name, "member": member.name}) @frappe.whitelist() def get_messages(batch): diff --git a/community/lms/doctype/lms_course/lms_course.py b/community/lms/doctype/lms_course/lms_course.py index 2a731337..a15ece81 100644 --- a/community/lms/doctype/lms_course/lms_course.py +++ b/community/lms/doctype/lms_course/lms_course.py @@ -124,6 +124,9 @@ class LMSCourse(Document): # TODO: chapters should have a way to specify the order return find_all("Chapter", course=self.name, order_by="creation") + def get_batch(self, batch_name): + return find("LMS Batch", name=batch_name, course=self.name) + def get_batches(self, mentor=None): batches = find_all("LMS Batch", course=self.name) if mentor: diff --git a/community/www/courses/about/index.html b/community/www/courses/about/index.html index ef417228..02d9336a 100644 --- a/community/www/courses/about/index.html +++ b/community/www/courses/about/index.html @@ -12,16 +12,13 @@ {{ Sidebar(course_slug, batch_code) }}
{{ CourseBasicDetail(course)}} - {{ InstructorsSection(instructor) }} - {% if batch.description %} - {{ BatchDetails(batch.description) }} - {% endif %} - {{ MentorsSection(mentors, True, course.name) }} + {{ InstructorsSection(course.get_instructor()) }} + {{ BatchDetails(batch)}}
{% endblock %} {% macro CourseBasicDetail(course) %} -

{{course.name}}

+

{{course.title}}

{{course.short_introduction}}
@@ -36,11 +33,25 @@
{{frappe.utils.md_to_html(course.description)}}
{% endmacro %} -{% macro BatchDetails(description) %} -
-

About the Batch

-
- {{ frappe.utils.md_to_html(description) }} -
+{% macro BatchDetails(batch) %} +

About the Batch

+ +
+
+
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 batch.get_mentors() %} +
+ {% if m.photo_url %} + + {% endif %} + {{m.full_name}} +
+ {% endfor %} +
{% endmacro %} diff --git a/community/www/courses/about/index.py b/community/www/courses/about/index.py index 780fee44..83b3df0e 100644 --- a/community/www/courses/about/index.py +++ b/community/www/courses/about/index.py @@ -1,21 +1,21 @@ import frappe -from community.www.courses.utils import redirect_if_not_a_member, get_course, get_instructor, get_batch +from community.lms.models import Course def get_context(context): context.no_cache = 1 - context.course_slug = frappe.form_dict["course"] - context.course = get_course(context.course_slug) - context.batch_code = frappe.form_dict["batch"] - redirect_if_not_a_member(context.course_slug, context.batch_code) - context.instructor = get_instructor(context.course.owner) - context.batch = get_batch(context.batch_code) - context.mentors = get_mentors(context.batch.name) + course_name = frappe.form_dict["course"] + batch_name = frappe.form_dict["batch"] -def get_mentors(batch): - mentors = [] - memberships = frappe.get_all("LMS Batch Membership", {"batch": batch, "member_type": "Mentor"}, ["member"]) - for membership in memberships: - member = frappe.get_doc("Community Member", membership.member) - mentors.append(member) - return mentors + course = Course.find(course_name) + if not course: + context.template = "www/404.html" + return + + batch = course.get_batch(batch_name) + if not batch: + frappe.local.flags.redirect_location = "/courses/" + course_name + raise frappe.Redirect + + context.course = course + context.batch = batch