From 65edd2ce224fdb0878246b1ce074676c73449472 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 8 Aug 2022 11:47:23 +0530 Subject: [PATCH] feat: new lesson redirect --- lms/hooks.py | 2 -- lms/lms/widgets/CourseOutline.html | 2 +- lms/patches.txt | 1 + lms/patches/v0_0/delete_course_web_forms.py | 6 +++++ lms/www/batch/learn.html | 29 ++++++++++++++++----- lms/www/batch/learn.py | 17 ++++++++++-- lms/www/courses/course.html | 4 +-- lms/www/courses/course.py | 4 +++ 8 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 lms/patches/v0_0/delete_course_web_forms.py diff --git a/lms/hooks.py b/lms/hooks.py index 20b63f0c..b1f7ab2b 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -135,8 +135,6 @@ website_route_rules = [ {"from_route": "/sketches/", "to_route": "sketches/sketch"}, {"from_route": "/courses/", "to_route": "courses/course"}, {"from_route": "/courses//", "to_route": "courses/certificate"}, - {"from_route": "/hackathons/", "to_route": "hackathons/hackathon"}, - {"from_route": "/hackathons//", "to_route": "hackathons/project"}, {"from_route": "/courses//learn", "to_route": "batch/learn"}, {"from_route": "/courses//learn/.", "to_route": "batch/learn"}, {"from_route": "/courses//progress", "to_route": "batch/progress"}, diff --git a/lms/lms/widgets/CourseOutline.html b/lms/lms/widgets/CourseOutline.html index 6f5d1131..6db8812a 100644 --- a/lms/lms/widgets/CourseOutline.html +++ b/lms/lms/widgets/CourseOutline.html @@ -35,7 +35,7 @@
- + {{ _("New Lesson") }}
{% endif %} diff --git a/lms/patches.txt b/lms/patches.txt index b1a8a44a..b8c513c6 100644 --- a/lms/patches.txt +++ b/lms/patches.txt @@ -29,3 +29,4 @@ execute:frappe.delete_doc("Workspace", "School", ignore_missing=True, force=True lms.patches.v0_0.move_certification_to_certificate lms.patches.v0_0.quiz_submission_member lms.patches.v0_0.delete_old_module_docs #08-07-2022 +lms.patches.v0_0.delete_course_web_forms diff --git a/lms/patches/v0_0/delete_course_web_forms.py b/lms/patches/v0_0/delete_course_web_forms.py new file mode 100644 index 00000000..ab965f62 --- /dev/null +++ b/lms/patches/v0_0/delete_course_web_forms.py @@ -0,0 +1,6 @@ +import frappe + +def execute(): + frappe.delete_doc("Web Form", "lesson", ignore_missing=True, force=True) + frappe.delete_doc("Web Form", "chapter", ignore_missing=True, force=True) + frappe.delete_doc("Web Form", "course", ignore_missing=True, force=True) diff --git a/lms/www/batch/learn.html b/lms/www/batch/learn.html index a35f7390..c4db7176 100644 --- a/lms/www/batch/learn.html +++ b/lms/www/batch/learn.html @@ -1,6 +1,16 @@ {% extends "templates/base.html" %} {% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %} -{% block title %} {{ lesson.title }} - {{ course.title }} {% endblock %} + +{% block title %} + +{% if lesson.title %} +{{ lesson.title }} - {{ course.title }} +{% else %} +{{ _("New Lesson") }} +{% endif %} + +{% endblock %} + {% block head_include %} {% include "public/icons/symbol-defs.svg" %} @@ -12,6 +22,7 @@ {% endblock %} + {% block content %}
@@ -29,25 +40,31 @@
{% endblock %} + + {% macro BreadCrumb(course, lesson) %} {% endmacro %} + + {% macro LessonContent(lesson) %} {% set instructors = get_instructors(course.name) %} {% set is_instructor = is_instructor(course.name) %}
-
{{ lesson.title }}
+ +
{% if lesson.title %} {{ lesson.title }} {% endif %}
{{ _("COMPLETED") }} {% if is_instructor %} diff --git a/lms/www/batch/learn.py b/lms/www/batch/learn.py index 648c94ea..c836ec06 100644 --- a/lms/www/batch/learn.py +++ b/lms/www/batch/learn.py @@ -3,7 +3,6 @@ import frappe from lms.www.utils import get_common_context, redirect_to_lesson from lms.lms.utils import get_lesson_url from frappe.utils import cstr, flt -from lms.www import batch def get_context(context): get_common_context(context) @@ -11,13 +10,22 @@ def get_context(context): chapter_index = frappe.form_dict.get("chapter") lesson_index = frappe.form_dict.get("lesson") lesson_number = f"{chapter_index}.{lesson_index}" - if not chapter_index or not lesson_index: + print(chapter_index, lesson_index, type(chapter_index), type(lesson_index)) + if (not chapter_index and chapter_index != 0) or (not lesson_index and lesson_index != 0): if context.batch: index_ = get_lesson_index(context.course, context.batch, frappe.session.user) or "1.1" else: index_ = "1.1" redirect_to_lesson(context.course, index_) + if chapter_index == 0 and lesson_index == 0: + context.lesson = frappe._dict() + context.lesson.edit_mode = True + else: + set_lesson_context(context, lesson_number) + + +def set_lesson_context(context, lesson_number): context.lesson = get_current_lesson_details(lesson_number, context) neighbours = get_neighbours(lesson_number, context.lessons) context.next_url = get_url(neighbours["next"], context.course) @@ -38,19 +46,23 @@ def get_context(context): "is_member": context.membership is not None } + def get_current_lesson_details(lesson_number, context): details_list = list(filter(lambda x: cstr(x.number) == lesson_number, context.lessons)) if not len(details_list): redirect_to_lesson(context.course) return details_list[0] + def get_url(lesson_number, course): return get_lesson_url(course.name, lesson_number) and get_lesson_url(course.name, lesson_number) + course.query_parameter + def get_lesson_index(course, batch, user): lesson = batch.get_current_lesson(user) return lesson and course.get_lesson_index(lesson) + def get_page_extensions(context): default_value = ["lms.plugins.PageExtension"] classnames = frappe.get_hooks("lms_lesson_page_extensions") or default_value @@ -59,6 +71,7 @@ def get_page_extensions(context): e.set_context(context) return extensions + def get_neighbours(current, lessons): current = flt(current) numbers = sorted(lesson.number for lesson in lessons) diff --git a/lms/www/courses/course.html b/lms/www/courses/course.html index a8dd1c53..0cc8c0a8 100644 --- a/lms/www/courses/course.html +++ b/lms/www/courses/course.html @@ -72,8 +72,8 @@ {% endif %}
-
{% if course.title %} {{ course.title }} {% endif %}
+
{% if course.title %} {{ course.title }} {% endif %}
{% if course.short_introduction %} {{ course.short_introduction }} {% endif %}
diff --git a/lms/www/courses/course.py b/lms/www/courses/course.py index c97cfa2a..94eed8f3 100644 --- a/lms/www/courses/course.py +++ b/lms/www/courses/course.py @@ -17,6 +17,7 @@ def get_context(context): else: set_course_context(context, course_name) + def set_course_context(context, course_name): course = frappe.db.get_value("LMS Course", course_name, ["name", "title", "image", "short_introduction", "description", "published", "upcoming", "disable_self_learning", @@ -61,15 +62,18 @@ def set_course_context(context, course_name): "keywords": course.title } + def get_user_interest(course): return frappe.db.count("LMS Course Interest", { "course": course, "user": frappe.session.user }) + def show_start_learing_cta(course, membership, restriction): return not course.disable_self_learning and not membership and not course.upcoming and not restriction.get("restrict") and not is_instructor(course.name) + def redirect_to_courses_list(): frappe.local.flags.redirect_location = "/courses" raise frappe.Redirect