From 68a1d1e436401766ea3670600f34146e42095d08 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 13 May 2024 16:50:52 +0530 Subject: [PATCH] fix: progress update --- frontend/src/pages/Lesson.vue | 2 +- lms/hooks.py | 5 -- .../doctype/course_lesson/course_lesson.py | 11 ++-- lms/lms/doctype/lms_badge/lms_badge.py | 12 ++--- lms/lms/doctype/lms_quiz/lms_quiz.py | 5 -- lms/public/frontend/index.html | 6 +-- lms/subscription_utils.py | 50 ------------------- lms/unsplash.py | 1 - 8 files changed, 15 insertions(+), 77 deletions(-) delete mode 100644 lms/subscription_utils.py diff --git a/frontend/src/pages/Lesson.vue b/frontend/src/pages/Lesson.vue index 3ef10bc1..120052d8 100644 --- a/frontend/src/pages/Lesson.vue +++ b/frontend/src/pages/Lesson.vue @@ -151,7 +151,7 @@
-
+
{{ lesson.data.course_title }}
diff --git a/lms/hooks.py b/lms/hooks.py index 36472024..0bb32c40 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -97,11 +97,6 @@ override_doctype_class = { # Hook on document methods and events doc_events = { - "*": { - "on_change": [ - "lms.lms.doctype.lms_badge.lms_badge.process_badges", - ] - }, "Discussion Reply": {"after_insert": "lms.lms.utils.handle_notifications"}, } diff --git a/lms/lms/doctype/course_lesson/course_lesson.py b/lms/lms/doctype/course_lesson/course_lesson.py index 4b93c2ff..de50991f 100644 --- a/lms/lms/doctype/course_lesson/course_lesson.py +++ b/lms/lms/doctype/course_lesson/course_lesson.py @@ -89,14 +89,14 @@ class CourseLesson(Document): @frappe.whitelist() def save_progress(lesson, course): + print("save progress") membership = frappe.db.exists( - "LMS Enrollment", {"member": frappe.session.user, "course": course} + "LMS Enrollment", {"course": course, "member": frappe.session.user} ) if not membership: return 0 quiz_completed = get_quiz_progress(lesson) - if not quiz_completed: return 0 @@ -115,7 +115,12 @@ def save_progress(lesson, course): ).save(ignore_permissions=True) progress = get_course_progress(course) - frappe.db.set_value("LMS Enrollment", membership, "progress", progress) + print(membership) + enrollment = frappe.get_doc("LMS Enrollment", membership) + print(enrollment.progress) + print(progress) + enrollment.progress = progress + enrollment.save(ignore_permissions=True) return progress diff --git a/lms/lms/doctype/lms_badge/lms_badge.py b/lms/lms/doctype/lms_badge/lms_badge.py index b8924c9c..30ad7c03 100644 --- a/lms/lms/doctype/lms_badge/lms_badge.py +++ b/lms/lms/doctype/lms_badge/lms_badge.py @@ -8,31 +8,25 @@ from frappe.model.document import Document class LMSBadge(Document): def apply(self, doc): if self.rule_condition_satisfied(doc): - print("rule satisfied") self.award(doc) def rule_condition_satisfied(self, doc): doc_before_save = doc.get_doc_before_save() - print(doc_before_save.as_dict()) - print(doc.as_dict()) + if self.event == "New" and doc_before_save != None: return False - print("its new") + if self.event == "Value Change": field_to_check = self.field_to_check - print(field_to_check) if not field_to_check: return False - print(doc_before_save.get(field_to_check)) - print(doc.get(field_to_check)) + print(doc_before_save.get(field_to_check), doc.get(field_to_check)) if doc_before_save and doc_before_save.get(field_to_check) == doc.get( field_to_check ): return False if self.condition: - print("found condition") - print(self.eval_condition(doc)) return self.eval_condition(doc) return False diff --git a/lms/lms/doctype/lms_quiz/lms_quiz.py b/lms/lms/doctype/lms_quiz/lms_quiz.py index 2e23eabe..67b253b3 100644 --- a/lms/lms/doctype/lms_quiz/lms_quiz.py +++ b/lms/lms/doctype/lms_quiz/lms_quiz.py @@ -105,18 +105,13 @@ def quiz_summary(quiz, results): ) submission.save(ignore_permissions=True) - print( - percentage, quiz_details.passing_percentage, quiz_details.lesson, quiz_details.course - ) if ( percentage >= quiz_details.passing_percentage and quiz_details.lesson and quiz_details.course ): - print("if") save_progress(quiz_details.lesson, quiz_details.course) elif not quiz_details.passing_percentage: - print("elif") save_progress(quiz_details.lesson, quiz_details.course) return { diff --git a/lms/public/frontend/index.html b/lms/public/frontend/index.html index b0b891c1..a5271db1 100644 --- a/lms/public/frontend/index.html +++ b/lms/public/frontend/index.html @@ -15,10 +15,10 @@ - - + + - +
diff --git a/lms/subscription_utils.py b/lms/subscription_utils.py deleted file mode 100644 index 35971180..00000000 --- a/lms/subscription_utils.py +++ /dev/null @@ -1,50 +0,0 @@ -import frappe - - -@frappe.whitelist(allow_guest=True) -def get_add_on_details(plan: str) -> dict[str, int]: - """ - Returns the number of courses and course members to be billed under add-ons for SAAS subscription - """ - - return {"courses": get_add_on_courses(plan), "members": get_add_on_members(plan)} - - -def get_published_courses() -> int: - return frappe.db.count("LMS Course", {"published": 1}) - - -def get_add_on_courses(plan: str) -> int: - COURSE_LIMITS = {"Lite": 5, "Pro": 20} - add_on_courses = 0 - courses_included_in_plans = COURSE_LIMITS.get(plan) - - if courses_included_in_plans: - published_courses = get_published_courses() - add_on_courses = ( - published_courses - courses_included_in_plans - if published_courses > courses_included_in_plans - else 0 - ) - - return add_on_courses - - -def get_add_on_members(plan: str) -> int: - MEMBER_LIMITS = {"Lite": 500, "Pro": 1000} - add_on_members = 0 - members_included_in_plans = MEMBER_LIMITS.get(plan) - - if members_included_in_plans: - active_members = get_members() - add_on_members = ( - active_members - members_included_in_plans - if active_members > members_included_in_plans - else 0 - ) - - return add_on_members - - -def get_members() -> int: - return frappe.db.count("LMS Enrollment") diff --git a/lms/unsplash.py b/lms/unsplash.py index 00cffdd9..603443bf 100644 --- a/lms/unsplash.py +++ b/lms/unsplash.py @@ -30,7 +30,6 @@ def make_unsplash_request(path): import requests url = f"{base_url}{path}" - print(url) res = requests.get( url, headers={