From 6dd12e111db3e2d109807321c043a19453cffb30 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 28 Jul 2022 18:22:57 +0530 Subject: [PATCH 01/16] feat: new course ui --- lms/hooks.py | 3 +- .../job_opportunity/job_opportunity.json | 5 +- lms/lms/doctype/lms_course/lms_course.py | 45 +++ lms/lms/utils.py | 14 + lms/lms/widgets/CourseOutline.html | 173 +++++------ lms/lms/widgets/NoPreviewModal.html | 32 ++ lms/public/css/style.css | 42 ++- lms/www/courses/course.js | 285 ++++++++++++------ lms/www/courses/course.py | 13 +- lms/www/dashboard/index.html | 2 +- 10 files changed, 421 insertions(+), 193 deletions(-) create mode 100644 lms/lms/widgets/NoPreviewModal.html diff --git a/lms/hooks.py b/lms/hooks.py index 2ecdb1df..20b63f0c 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -190,7 +190,8 @@ jinja = { "lms.lms.utils.convert_number_to_character", "lms.lms.utils.get_signup_optin_checks", "lms.lms.utils.get_popular_courses", - "lms.lms.utils.format_amount" + "lms.lms.utils.format_amount", + "lms.lms.utils.first_lesson_exists" ], "filters": [] } diff --git a/lms/job/doctype/job_opportunity/job_opportunity.json b/lms/job/doctype/job_opportunity/job_opportunity.json index aa712661..e4e0e1b5 100644 --- a/lms/job/doctype/job_opportunity/job_opportunity.json +++ b/lms/job/doctype/job_opportunity/job_opportunity.json @@ -1,5 +1,6 @@ { "actions": [], + "allow_import": 1, "allow_rename": 1, "autoname": "format: JOB-{#####}", "creation": "2022-02-07 12:01:41.074418", @@ -13,7 +14,7 @@ "column_break_5", "type", "status", - "section_break_6", + "section_break_6",`` "description", "company_details_section", "company_name", @@ -113,7 +114,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-02-24 12:37:45.666484", + "modified": "2022-07-28 13:41:29.224332", "modified_by": "Administrator", "module": "Job", "name": "Job Opportunity", diff --git a/lms/lms/doctype/lms_course/lms_course.py b/lms/lms/doctype/lms_course/lms_course.py index 5e4a5df2..322cb77c 100644 --- a/lms/lms/doctype/lms_course/lms_course.py +++ b/lms/lms/doctype/lms_course/lms_course.py @@ -2,6 +2,7 @@ # For license information, please see license.txt from __future__ import unicode_literals +from codecs import ignore_errors import frappe from frappe.model.document import Document import json @@ -203,3 +204,47 @@ def submit_for_review(course): return "No Chp" frappe.db.set_value("LMS Course", course, "status", "Under Review") return "OK" + + +@frappe.whitelist() +def save_course(tags, title, short_introduction, video_link, image, description, course): + if course: + doc = frappe.get_doc("LMS Course", course) + else: + doc = frappe.get_doc({ + "doctype": "LMS Course" + }) + + doc.update({ + "title": title, + "short_introduction": short_introduction, + "video_link": video_link, + "image": image, + "description": description, + "tags": tags + }) + doc.save(ignore_permissions=True) + return doc.name + + +@frappe.whitelist() +def save_chapter(course, chapter, chapter_description, idx): + chapter = frappe.get_doc({ + "doctype": "Course Chapter", + "course": course, + "title": chapter, + "description": chapter_description + }) + chapter.save(ignore_permissions=True) + + chapter_reference = frappe.get_doc({ + "doctype": "Chapter Reference", + "parent": course, + "chapter": chapter.name, + "parenttype": "LMS Course", + "parentfield": "chapters", + "idx": idx + }) + chapter_reference.save(ignore_permissions=True) + + return chapter.name diff --git a/lms/lms/utils.py b/lms/lms/utils.py index 129737fc..57a1f906 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -53,6 +53,8 @@ def get_membership(course, member, batch=None): def get_chapters(course): """Returns all chapters of this course. """ + if not course: + return [] chapters = frappe.get_all("Chapter Reference", {"parent": course}, ["idx", "chapter"], order_by="idx") for chapter in chapters: @@ -373,3 +375,15 @@ def format_amount(amount, currency): return amount precision = 0 if amount % 1000 == 0 else 1 return _("{0}k").format(fmt_money(amount_reduced, precision, currency)) + + +def first_lesson_exists(course): + first_chapter = frappe.db.get_value("Chapter Reference", {"parent": course, "idx": 1}, "name") + if not first_chapter: + return False + + first_lesson = frappe.db.get_value("Lesson Reference", {"parent": first_chapter, "idx": 1}, "name") + if not first_lesson: + return False + + return True diff --git a/lms/lms/widgets/CourseOutline.html b/lms/lms/widgets/CourseOutline.html index 1aedcb2e..b2de2df0 100644 --- a/lms/lms/widgets/CourseOutline.html +++ b/lms/lms/widgets/CourseOutline.html @@ -1,109 +1,98 @@ {% if get_chapters(course.name) | length %}
-
- {{ _("Course Content") }} -
- {% for chapter in get_chapters(course.name) %} -
-