From ebc3cf1cbf0ec598c0266a12484a0025e365a217 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Thu, 30 Sep 2021 18:31:41 +0530 Subject: [PATCH] feat: live and upcoming course headers --- community/www/courses/index.html | 19 +++++++++++++++++-- community/www/courses/index.py | 16 +++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/community/www/courses/index.html b/community/www/courses/index.html index 991108e5..07d5b5e7 100644 --- a/community/www/courses/index.html +++ b/community/www/courses/index.html @@ -9,14 +9,29 @@ {% block content %}
+ + {% if live_courses | length %}
- {{ 'All Courses' }} + {{ _('Live Courses') }}
- {% for course in courses %} + {% for course in live_courses %} {{ widgets.CourseCard(course=course, read_only=False) }} {% endfor %}
+ {% endif %} + + {% if upcoming_courses | length %} +
+ {{ _('Upcoming Courses') }} +
+
+ {% for course in upcoming_courses %} + {{ widgets.CourseCard(course=course, read_only=False) }} + {% endfor %} +
+ {% endif %} +
{% endblock %} diff --git a/community/www/courses/index.py b/community/www/courses/index.py index 6cc72787..f4981077 100644 --- a/community/www/courses/index.py +++ b/community/www/courses/index.py @@ -2,7 +2,7 @@ import frappe def get_context(context): context.no_cache = 1 - context.courses = get_courses() + context.live_courses, context.upcoming_courses = get_courses() context.metatags = { "title": "All Courses", "image": frappe.db.get_single_value("Website Settings", "banner_image"), @@ -11,8 +11,14 @@ def get_context(context): } def get_courses(): - course_names = frappe.get_all("LMS Course", filters={"is_published": True}, order_by="upcoming", pluck="name") - courses = [] + course_names = frappe.get_all("LMS Course", + filters={"is_published": True}, + fields=["name", "upcoming"]) + + live_courses, upcoming_courses = [], [] for course in course_names: - courses.append(frappe.get_doc("LMS Course", course)) - return courses + if course.upcoming: + upcoming_courses.append(frappe.get_doc("LMS Course", course.name)) + else: + live_courses.append(frappe.get_doc("LMS Course", course.name)) + return live_courses, upcoming_courses