From dcd81e0a3f08a5ec179f94498f622edb0d02920b Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Tue, 6 Jun 2023 22:06:01 +0530 Subject: [PATCH 1/2] fix: onboarding links --- lms/hooks.py | 1 + lms/lms/utils.py | 17 +++++++++++++++ lms/templates/onboarding_header.html | 32 ++++++++-------------------- lms/www/batch/edit.html | 2 +- lms/www/courses/create.html | 2 +- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/lms/hooks.py b/lms/hooks.py index 07b8d74b..3a20df76 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -240,6 +240,7 @@ jinja = { "lms.lms.utils.show_start_learing_cta", "lms.lms.utils.can_create_courses", "lms.lms.utils.get_telemetry_boot_info", + "lms.lms.utils.is_onboarding_complete", ], "filters": [], } diff --git a/lms/lms/utils.py b/lms/lms/utils.py index effa09cd..29a6bbd8 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -714,3 +714,20 @@ def get_telemetry_boot_info(): "posthog_project_id": frappe.conf.get(POSTHOG_PROJECT_FIELD), "enable_telemetry": 1, } + + +def is_onboarding_complete(): + course_created = frappe.db.a_row_exists("LMS Course") + chapter_created = frappe.db.a_row_exists("Course Chapter") + lesson_created = frappe.db.a_row_exists("Course Lesson") + + if course_created and chapter_created and lesson_created: + frappe.db.set_value("LMS Settings", "is_onboarding_complete", 1) + + return { + "is_onboarded": frappe.db.get_single_value("LMS Settings", "is_onboarding_complete"), + "course_created": course_created, + "chapter_created": chapter_created, + "lesson_created": lesson_created, + "first_course": frappe.get_all("LMS Course", limit=1, order_by=None, pluck="name"), + } diff --git a/lms/templates/onboarding_header.html b/lms/templates/onboarding_header.html index 7beb6b1d..2461e3f8 100644 --- a/lms/templates/onboarding_header.html +++ b/lms/templates/onboarding_header.html @@ -1,13 +1,6 @@ -{% set onboarding_settings = frappe.db.get_single_value("LMS Settings", "is_onboarding_complete") %} -{% set course_created = frappe.db.count("LMS Course") %} -{% set chapter_created = frappe.db.count("Course Chapter") %} -{% set lesson_created = frappe.db.count("Course Lesson") %} -{% set quiz_created = frappe.db.count("LMS Quiz") %} -{% set first_course = frappe.db.get_all("LMS Course", order_by="creation", pluck="name")[0] %} - -{% set is_onboarding_complete = onboarding_settings or (course_created and chapter_created and lesson_created and quiz_created) %} - -{% if has_course_moderator_role() and not is_onboarding_complete %} +{% set onboarding_status = is_onboarding_complete() %} +{{ onboarding_status.is_onboarded }} +{% if has_course_moderator_role() and not onboarding_status.is_onboarded %}
{{ _("Skip") }}
@@ -18,34 +11,27 @@ {{ _("Lets start setting up your content on the LMS so that you can reclaim time and focus on growth.") }}
diff --git a/lms/www/batch/edit.html b/lms/www/batch/edit.html index 85a333e1..44454396 100644 --- a/lms/www/batch/edit.html +++ b/lms/www/batch/edit.html @@ -8,7 +8,7 @@ {% endif %} {% endblock %} -{% block content %} +{% block page_content %}
{{ Header() }}
diff --git a/lms/www/courses/create.html b/lms/www/courses/create.html index 716441e3..fb803672 100644 --- a/lms/www/courses/create.html +++ b/lms/www/courses/create.html @@ -3,7 +3,7 @@ {{ course.title if course and course.title else _("New Course") }} {% endblock %} -{% block content %} +{% block page_content %}
{{ Header() }}
From c2e9ef59d675a6c4ace7a3d0e92accc5d5e9bf09 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 7 Jun 2023 15:43:44 +0530 Subject: [PATCH 2/2] fix: onboarding conditions --- lms/lms/utils.py | 6 ++++-- lms/templates/onboarding_header.html | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lms/lms/utils.py b/lms/lms/utils.py index 29a6bbd8..522084fe 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -722,12 +722,14 @@ def is_onboarding_complete(): lesson_created = frappe.db.a_row_exists("Course Lesson") if course_created and chapter_created and lesson_created: - frappe.db.set_value("LMS Settings", "is_onboarding_complete", 1) + frappe.db.set_single_value("LMS Settings", "is_onboarding_complete", 1) return { "is_onboarded": frappe.db.get_single_value("LMS Settings", "is_onboarding_complete"), "course_created": course_created, "chapter_created": chapter_created, "lesson_created": lesson_created, - "first_course": frappe.get_all("LMS Course", limit=1, order_by=None, pluck="name"), + "first_course": frappe.get_all("LMS Course", limit=1, order_by=None, pluck="name")[0] + if course_created + else None, } diff --git a/lms/templates/onboarding_header.html b/lms/templates/onboarding_header.html index 2461e3f8..204e36ee 100644 --- a/lms/templates/onboarding_header.html +++ b/lms/templates/onboarding_header.html @@ -1,5 +1,5 @@ {% set onboarding_status = is_onboarding_complete() %} -{{ onboarding_status.is_onboarded }} + {% if has_course_moderator_role() and not onboarding_status.is_onboarded %}