From 5e973b21ae3a0b13442a89095cb60cc8ad5b7253 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 7 Mar 2022 18:21:11 +0530 Subject: [PATCH 01/24] feat: course web form --- school/lms/doctype/lms_course/lms_course.json | 17 ++- school/lms/web_form/course/__init__.py | 0 school/lms/web_form/course/course.js | 3 + school/lms/web_form/course/course.json | 125 ++++++++++++++++++ school/lms/web_form/course/course.py | 5 + 5 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 school/lms/web_form/course/__init__.py create mode 100644 school/lms/web_form/course/course.js create mode 100644 school/lms/web_form/course/course.json create mode 100644 school/lms/web_form/course/course.py diff --git a/school/lms/doctype/lms_course/lms_course.json b/school/lms/doctype/lms_course/lms_course.json index 84abccb2..61ce2ca7 100644 --- a/school/lms/doctype/lms_course/lms_course.json +++ b/school/lms/doctype/lms_course/lms_course.json @@ -10,7 +10,7 @@ "allow_guest_to_view": 1, "allow_import": 1, "allow_rename": 1, - "creation": "2022-02-08 16:34:42.721203", + "creation": "2022-02-22 15:28:26.091549", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", @@ -174,7 +174,7 @@ "link_fieldname": "course" } ], - "modified": "2022-02-16 11:50:20.661085", + "modified": "2022-03-07 14:47:51.745509", "modified_by": "Administrator", "module": "LMS", "name": "LMS Course", @@ -191,6 +191,19 @@ "role": "System Manager", "share": 1, "write": 1 + }, + { + "create": 1, + "email": 1, + "export": 1, + "if_owner": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "All", + "select": 1, + "share": 1, + "write": 1 } ], "search_fields": "title", diff --git a/school/lms/web_form/course/__init__.py b/school/lms/web_form/course/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/school/lms/web_form/course/course.js b/school/lms/web_form/course/course.js new file mode 100644 index 00000000..699703c5 --- /dev/null +++ b/school/lms/web_form/course/course.js @@ -0,0 +1,3 @@ +frappe.ready(function() { + // bind events here +}) \ No newline at end of file diff --git a/school/lms/web_form/course/course.json b/school/lms/web_form/course/course.json new file mode 100644 index 00000000..3c6df39c --- /dev/null +++ b/school/lms/web_form/course/course.json @@ -0,0 +1,125 @@ +{ + "accept_payment": 0, + "allow_comments": 0, + "allow_delete": 0, + "allow_edit": 1, + "allow_incomplete": 0, + "allow_multiple": 1, + "allow_print": 0, + "amount": 0.0, + "amount_based_on_field": 0, + "apply_document_permissions": 1, + "button_label": "Save", + "creation": "2022-03-07 14:40:41.262163", + "custom_css": "", + "doc_type": "LMS Course", + "docstatus": 0, + "doctype": "Web Form", + "idx": 0, + "is_multi_step_form": 0, + "is_standard": 1, + "login_required": 1, + "max_attachment_size": 0, + "modified": "2022-03-07 14:48:04.889844", + "modified_by": "Administrator", + "module": "LMS", + "name": "course", + "owner": "Administrator", + "payment_button_label": "Buy Now", + "published": 1, + "route": "course", + "route_to_success_link": 0, + "show_attachments": 0, + "show_in_grid": 0, + "show_sidebar": 0, + "sidebar_items": [], + "success_url": "/course", + "title": "Course", + "web_form_fields": [ + { + "allow_read_on_all_link_options": 0, + "fieldname": "title", + "fieldtype": "Data", + "hidden": 0, + "label": "Title", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 1, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "video_link", + "fieldtype": "Data", + "hidden": 0, + "label": "Video Embed Link", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 0, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "image", + "fieldtype": "Attach Image", + "hidden": 0, + "label": "Preview Image", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 0, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "tags", + "fieldtype": "Data", + "hidden": 0, + "label": "Tags", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 0, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "short_introduction", + "fieldtype": "Small Text", + "hidden": 0, + "label": "Short Introduction", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 1, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "description", + "fieldtype": "Data", + "hidden": 0, + "label": "Description", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 1, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "chapters", + "fieldtype": "Table", + "hidden": 0, + "label": "Chapters", + "max_length": 0, + "max_value": 0, + "options": "Chapter Reference", + "read_only": 0, + "reqd": 0, + "show_in_filter": 0 + } + ] +} \ No newline at end of file diff --git a/school/lms/web_form/course/course.py b/school/lms/web_form/course/course.py new file mode 100644 index 00000000..e1ada619 --- /dev/null +++ b/school/lms/web_form/course/course.py @@ -0,0 +1,5 @@ +import frappe + +def get_context(context): + # do your magic here + pass From 3bdf6df70d5f5f35ac631f036c4bdc1fe0fb13d9 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 7 Mar 2022 18:28:12 +0530 Subject: [PATCH 02/24] fix: allow locked lessons o instructors through outline --- school/lms/widgets/CourseOutline.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/school/lms/widgets/CourseOutline.html b/school/lms/widgets/CourseOutline.html index e4144d62..d80b7f9a 100644 --- a/school/lms/widgets/CourseOutline.html +++ b/school/lms/widgets/CourseOutline.html @@ -19,7 +19,7 @@ {% endif %} - {% set is_instructor = frappe.session.user == course.instructor %} + {% set is_instructor = is_instructor(course.name) %}
{% for lesson in get_lessons(course.name, chapter) %} @@ -41,7 +41,7 @@ {% elif is_instructor and not lesson.include_in_preview %}
{{ lesson.title }}
From 8f9cd729758782afbe7416814c0a2ee2a6262c95 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 9 Mar 2022 12:29:03 +0530 Subject: [PATCH 03/24] feat: course creation from ui --- .../course_chapter/course_chapter.json | 18 +++- .../doctype/course_lesson/course_lesson.json | 21 ++++- .../doctype/course_lesson/course_lesson.py | 12 ++- school/lms/doctype/lms_course/lms_course.json | 5 +- school/lms/web_form/chapter/__init__.py | 0 school/lms/web_form/chapter/chapter.js | 3 + school/lms/web_form/chapter/chapter.json | 89 ++++++++++++++++++ school/lms/web_form/chapter/chapter.py | 5 + school/lms/web_form/course/course.js | 8 +- school/lms/web_form/course/course.json | 30 +++++- school/lms/web_form/lesson/__init__.py | 0 school/lms/web_form/lesson/lesson.js | 17 ++++ school/lms/web_form/lesson/lesson.json | 91 +++++++++++++++++++ school/lms/web_form/lesson/lesson.py | 5 + school/www/batch/learn.html | 5 +- school/www/courses/course.html | 7 ++ 16 files changed, 300 insertions(+), 16 deletions(-) create mode 100644 school/lms/web_form/chapter/__init__.py create mode 100644 school/lms/web_form/chapter/chapter.js create mode 100644 school/lms/web_form/chapter/chapter.json create mode 100644 school/lms/web_form/chapter/chapter.py create mode 100644 school/lms/web_form/lesson/__init__.py create mode 100644 school/lms/web_form/lesson/lesson.js create mode 100644 school/lms/web_form/lesson/lesson.json create mode 100644 school/lms/web_form/lesson/lesson.py diff --git a/school/lms/doctype/course_chapter/course_chapter.json b/school/lms/doctype/course_chapter/course_chapter.json index 7dca741a..1b5395c0 100644 --- a/school/lms/doctype/course_chapter/course_chapter.json +++ b/school/lms/doctype/course_chapter/course_chapter.json @@ -59,7 +59,7 @@ "link_fieldname": "chapter" } ], - "modified": "2021-09-29 15:33:44.611229", + "modified": "2022-03-08 15:21:10.389729", "modified_by": "Administrator", "module": "LMS", "name": "Course Chapter", @@ -77,11 +77,25 @@ "role": "System Manager", "share": 1, "write": 1 + }, + { + "create": 1, + "email": 1, + "export": 1, + "if_owner": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "All", + "select": 1, + "share": 1, + "write": 1 } ], "search_fields": "title", "sort_field": "modified", "sort_order": "DESC", + "states": [], "title_field": "title", "track_changes": 1 -} +} \ No newline at end of file diff --git a/school/lms/doctype/course_lesson/course_lesson.json b/school/lms/doctype/course_lesson/course_lesson.json index d63eb69b..fd113a0c 100644 --- a/school/lms/doctype/course_lesson/course_lesson.json +++ b/school/lms/doctype/course_lesson/course_lesson.json @@ -1,6 +1,6 @@ { "actions": [], - "allow_import": 1, + "allow_events_in_timeline": 1, "allow_rename": 1, "autoname": "format:{####} {title}", "creation": "2021-05-03 06:21:12.995984", @@ -73,7 +73,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-10-11 15:07:38.134808", + "modified": "2022-03-08 17:56:50.504143", "modified_by": "Administrator", "module": "LMS", "name": "Course Lesson", @@ -89,11 +89,26 @@ "read": 1, "report": 1, "role": "System Manager", + "select": 1, + "share": 1, + "write": 1 + }, + { + "create": 1, + "email": 1, + "export": 1, + "if_owner": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "All", + "select": 1, "share": 1, "write": 1 } ], "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 -} +} \ No newline at end of file diff --git a/school/lms/doctype/course_lesson/course_lesson.py b/school/lms/doctype/course_lesson/course_lesson.py index 38adb6a3..cd20613e 100644 --- a/school/lms/doctype/course_lesson/course_lesson.py +++ b/school/lms/doctype/course_lesson/course_lesson.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from ...md import find_macros -from school.lms.utils import get_course_progress +from school.lms.utils import get_course_progress, get_lesson_url class CourseLesson(Document): def validate(self): @@ -108,3 +108,13 @@ def save_progress(lesson, course, status): progress = get_course_progress(course) frappe.db.set_value("LMS Batch Membership", membership, "progress", progress) return progress + +@frappe.whitelist() +def get_lesson_info(lesson_name): + chapter = frappe.db.get_value("Course Lesson", lesson_name, "chapter") + course = frappe.db.get_value("Course Chapter", chapter, "course") + + lesson_idx = frappe.db.get_value("Lesson Reference", {"lesson": lesson_name}, ["idx"]) + chapter_idx = frappe.db.get_value("Chapter Reference", {"chapter": chapter}, ["idx"]) + + return get_lesson_url(course, f"{chapter_idx}.{lesson_idx}") diff --git a/school/lms/doctype/lms_course/lms_course.json b/school/lms/doctype/lms_course/lms_course.json index 61ce2ca7..b40ac09b 100644 --- a/school/lms/doctype/lms_course/lms_course.json +++ b/school/lms/doctype/lms_course/lms_course.json @@ -7,7 +7,6 @@ "label": "Reindex Exercises" } ], - "allow_guest_to_view": 1, "allow_import": 1, "allow_rename": 1, "creation": "2022-02-22 15:28:26.091549", @@ -150,7 +149,6 @@ "options": "Related Courses" } ], - "index_web_pages_for_search": 1, "is_published_field": "is_published", "links": [ { @@ -174,7 +172,7 @@ "link_fieldname": "course" } ], - "modified": "2022-03-07 14:47:51.745509", + "modified": "2022-03-08 15:20:58.501082", "modified_by": "Administrator", "module": "LMS", "name": "LMS Course", @@ -189,6 +187,7 @@ "read": 1, "report": 1, "role": "System Manager", + "select": 1, "share": 1, "write": 1 }, diff --git a/school/lms/web_form/chapter/__init__.py b/school/lms/web_form/chapter/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/school/lms/web_form/chapter/chapter.js b/school/lms/web_form/chapter/chapter.js new file mode 100644 index 00000000..699703c5 --- /dev/null +++ b/school/lms/web_form/chapter/chapter.js @@ -0,0 +1,3 @@ +frappe.ready(function() { + // bind events here +}) \ No newline at end of file diff --git a/school/lms/web_form/chapter/chapter.json b/school/lms/web_form/chapter/chapter.json new file mode 100644 index 00000000..a1db2177 --- /dev/null +++ b/school/lms/web_form/chapter/chapter.json @@ -0,0 +1,89 @@ +{ + "accept_payment": 0, + "allow_comments": 0, + "allow_delete": 0, + "allow_edit": 1, + "allow_incomplete": 0, + "allow_multiple": 1, + "allow_print": 0, + "amount": 0.0, + "amount_based_on_field": 0, + "apply_document_permissions": 0, + "button_label": "Save", + "creation": "2022-03-07 18:41:07.058806", + "doc_type": "Course Chapter", + "docstatus": 0, + "doctype": "Web Form", + "idx": 0, + "is_multi_step_form": 0, + "is_standard": 1, + "login_required": 1, + "max_attachment_size": 0, + "modified": "2022-03-07 18:41:07.058806", + "modified_by": "Administrator", + "module": "LMS", + "name": "chapter", + "owner": "Administrator", + "payment_button_label": "Buy Now", + "published": 1, + "route": "chapter", + "route_to_success_link": 0, + "show_attachments": 0, + "show_in_grid": 0, + "show_sidebar": 0, + "sidebar_items": [], + "success_url": "/chapter", + "title": "Chapter", + "web_form_fields": [ + { + "allow_read_on_all_link_options": 0, + "fieldname": "course", + "fieldtype": "Link", + "hidden": 0, + "label": "Course", + "max_length": 0, + "max_value": 0, + "options": "LMS Course", + "read_only": 0, + "reqd": 1, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "title", + "fieldtype": "Data", + "hidden": 0, + "label": "Title", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 1, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "description", + "fieldtype": "Small Text", + "hidden": 0, + "label": "Description", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 0, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "lessons", + "fieldtype": "Table", + "hidden": 0, + "label": "Lessons", + "max_length": 0, + "max_value": 0, + "options": "Lesson Reference", + "read_only": 0, + "reqd": 0, + "show_in_filter": 0 + } + ] +} \ No newline at end of file diff --git a/school/lms/web_form/chapter/chapter.py b/school/lms/web_form/chapter/chapter.py new file mode 100644 index 00000000..e1ada619 --- /dev/null +++ b/school/lms/web_form/chapter/chapter.py @@ -0,0 +1,5 @@ +import frappe + +def get_context(context): + # do your magic here + pass diff --git a/school/lms/web_form/course/course.js b/school/lms/web_form/course/course.js index 699703c5..23ad7a61 100644 --- a/school/lms/web_form/course/course.js +++ b/school/lms/web_form/course/course.js @@ -1,3 +1,7 @@ frappe.ready(function() { - // bind events here -}) \ No newline at end of file + frappe.web_form.after_save = () => { + setTimeout(() => { + window.location.href = `/courses/${frappe.web_form.doc.name}`; + }) + } +}); diff --git a/school/lms/web_form/course/course.json b/school/lms/web_form/course/course.json index 3c6df39c..01eb9e76 100644 --- a/school/lms/web_form/course/course.json +++ b/school/lms/web_form/course/course.json @@ -20,7 +20,7 @@ "is_standard": 1, "login_required": 1, "max_attachment_size": 0, - "modified": "2022-03-07 14:48:04.889844", + "modified": "2022-03-09 10:10:30.069458", "modified_by": "Administrator", "module": "LMS", "name": "course", @@ -48,6 +48,29 @@ "reqd": 1, "show_in_filter": 0 }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "tags", + "fieldtype": "Data", + "hidden": 0, + "label": "Tags", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 0, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "", + "fieldtype": "Column Break", + "hidden": 0, + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 0, + "show_in_filter": 0 + }, { "allow_read_on_all_link_options": 0, "fieldname": "video_link", @@ -74,10 +97,9 @@ }, { "allow_read_on_all_link_options": 0, - "fieldname": "tags", - "fieldtype": "Data", + "fieldname": "", + "fieldtype": "Section Break", "hidden": 0, - "label": "Tags", "max_length": 0, "max_value": 0, "read_only": 0, diff --git a/school/lms/web_form/lesson/__init__.py b/school/lms/web_form/lesson/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/school/lms/web_form/lesson/lesson.js b/school/lms/web_form/lesson/lesson.js new file mode 100644 index 00000000..afc067af --- /dev/null +++ b/school/lms/web_form/lesson/lesson.js @@ -0,0 +1,17 @@ +frappe.ready(function() { + frappe.web_form.after_save = () => { + setTimeout(() => { + + frappe.call({ + method: "school.lms.doctype.course_lesson.course_lesson.get_lesson_info", + args: { + "lesson_name": frappe.web_form.doc.name + }, + callback: (data) => { + window.location.href = data.message; + } + }); + + }); + }; +}); diff --git a/school/lms/web_form/lesson/lesson.json b/school/lms/web_form/lesson/lesson.json new file mode 100644 index 00000000..0aebf239 --- /dev/null +++ b/school/lms/web_form/lesson/lesson.json @@ -0,0 +1,91 @@ +{ + "accept_payment": 0, + "allow_comments": 0, + "allow_delete": 0, + "allow_edit": 1, + "allow_incomplete": 0, + "allow_multiple": 1, + "allow_print": 0, + "amount": 0.0, + "amount_based_on_field": 0, + "apply_document_permissions": 1, + "button_label": "Save", + "creation": "2022-03-07 18:41:42.549831", + "custom_css": "", + "doc_type": "Course Lesson", + "docstatus": 0, + "doctype": "Web Form", + "idx": 0, + "introduction_text": "



Create lessons for your course. You can add some additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.


Content TypeSyntax
Video{{ Video(\"url_of_source\") }}
YouTube Video{{ YouTubeVideo(\"unique_embed_id\") }}
Exercise{{ Exercise(\"exercise_name\") }}
Quiz{{ Quiz(\"lms_quiz_name\") }}
Assignment{{ Assignment(\"id-filetype\") }}
", + "is_multi_step_form": 0, + "is_standard": 1, + "login_required": 1, + "max_attachment_size": 0, + "modified": "2022-03-09 09:55:58.406164", + "modified_by": "Administrator", + "module": "LMS", + "name": "lesson", + "owner": "Administrator", + "payment_button_label": "Buy Now", + "published": 1, + "route": "lesson", + "route_to_success_link": 0, + "show_attachments": 0, + "show_in_grid": 0, + "show_sidebar": 0, + "sidebar_items": [], + "success_url": "/lesson", + "title": "Lesson", + "web_form_fields": [ + { + "allow_read_on_all_link_options": 1, + "fieldname": "chapter", + "fieldtype": "Link", + "hidden": 0, + "label": "Course Chapter", + "max_length": 0, + "max_value": 0, + "options": "Course Chapter", + "read_only": 0, + "reqd": 1, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "title", + "fieldtype": "Data", + "hidden": 0, + "label": "Title", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 1, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "default": "0", + "fieldname": "include_in_preview", + "fieldtype": "Check", + "hidden": 0, + "label": "Include In Preview", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 0, + "show_in_filter": 0 + }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "body", + "fieldtype": "Data", + "hidden": 0, + "label": "Body", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 1, + "show_in_filter": 0 + } + ] +} \ No newline at end of file diff --git a/school/lms/web_form/lesson/lesson.py b/school/lms/web_form/lesson/lesson.py new file mode 100644 index 00000000..e1ada619 --- /dev/null +++ b/school/lms/web_form/lesson/lesson.py @@ -0,0 +1,5 @@ +import frappe + +def get_context(context): + # do your magic here + pass diff --git a/school/www/batch/learn.html b/school/www/batch/learn.html index 34a5bd52..cc6258ea 100644 --- a/school/www/batch/learn.html +++ b/school/www/batch/learn.html @@ -42,10 +42,13 @@ {% if membership or is_instructor %} eligible-for-submission {% endif %}" data-lesson="{{ lesson.name }}" data-course="{{ course.name }}">{{ lesson.title }}
COMPLETED + + {% if is_instructor %} + {{ _("Edit") }} + {% endif %}
- {% set instructors = instructors %} {% set ins_len = instructors | length %} {% for instructor in instructors %} {% if ins_len > 1 and loop.index == 1 %} diff --git a/school/www/courses/course.html b/school/www/courses/course.html index e76af9fa..2081ca52 100644 --- a/school/www/courses/course.html +++ b/school/www/courses/course.html @@ -1,9 +1,11 @@ {% extends "templates/base.html" %} {% block title %}{{ course.title }} {% endblock %} + {% block head_include %} {% endblock %} + {% block content %}
@@ -26,6 +28,11 @@ style=" {% if course.image %} background-position: center; background-size: cover; background-image: url({{ course.image }}); {% else %} background-color: var(--gray-200) {% endif %}">
+ {% if is_instructor(course.name) %} + {{ _("New Lesson") }} + {{ _("New Chapter") }} + {{ _("Edit") }} + {% endif %} {{ BreadCrumb(course) }} {{ CourseCardWide(course) }}
From fb72704a3339157f4f401a7f8b689bf549529b8c Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 9 Mar 2022 14:32:50 +0530 Subject: [PATCH 04/24] feat: cookie policy --- school/fixtures/custom_field.json | 4 +-- school/hooks.py | 3 +- .../doctype/lms_settings/lms_settings.json | 26 +++++++++++++++-- school/lms/utils.py | 28 +++++++++++++++++++ school/templates/signup-form.html | 21 +------------- 5 files changed, 57 insertions(+), 25 deletions(-) diff --git a/school/fixtures/custom_field.json b/school/fixtures/custom_field.json index 0eb474a6..c48b71f9 100644 --- a/school/fixtures/custom_field.json +++ b/school/fixtures/custom_field.json @@ -80,10 +80,10 @@ "in_standard_filter": 0, "insert_after": "country", "is_virtual": 0, - "label": "Acceptance for Terms of Use and/or Privacy Policy", + "label": "Acceptance for Terms and/or Policies", "length": 0, "mandatory_depends_on": null, - "modified": "2021-12-31 19:15:34.932910", + "modified": "2021-12-31 19:15:34.932911", "module": null, "name": "User-verify_terms", "no_copy": 0, diff --git a/school/hooks.py b/school/hooks.py index 63c792cb..53f67397 100644 --- a/school/hooks.py +++ b/school/hooks.py @@ -185,7 +185,8 @@ jinja = { "school.lms.utils.get_initial_members", "school.lms.utils.get_sorted_reviews", "school.lms.utils.is_instructor", - "school.lms.utils.convert_number_to_character" + "school.lms.utils.convert_number_to_character", + "school.lms.utils.get_signup_optin_checks" ], "filters": [] } diff --git a/school/lms/doctype/lms_settings/lms_settings.json b/school/lms/doctype/lms_settings/lms_settings.json index 35c07925..53197ad4 100644 --- a/school/lms/doctype/lms_settings/lms_settings.json +++ b/school/lms/doctype/lms_settings/lms_settings.json @@ -13,9 +13,12 @@ "signup_settings_section", "terms_of_use", "terms_page", - "column_break_12", + "column_break_9", "privacy_policy", "privacy_policy_page", + "column_break_12", + "cookie_policy", + "cookie_policy_page", "mentor_request_section", "mentor_request_creation", "mentor_request_status_update" @@ -96,17 +99,36 @@ "fieldname": "privacy_policy_page", "fieldtype": "Link", "label": "Privacy Policy Page", + "mandatory_depends_on": "privacy_policy", "options": "Web Page" }, { "fieldname": "column_break_12", "fieldtype": "Column Break" + }, + { + "fieldname": "column_break_9", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "cookie_policy", + "fieldtype": "Check", + "label": "Show Cookie Policy on Signup" + }, + { + "depends_on": "cookie_policy", + "fieldname": "cookie_policy_page", + "fieldtype": "Link", + "label": "Cookie Policy Page", + "mandatory_depends_on": "cookie_policy", + "options": "Web Page" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2022-02-23 16:15:28.586903", + "modified": "2022-03-09 12:40:27.464136", "modified_by": "Administrator", "module": "LMS", "name": "LMS Settings", diff --git a/school/lms/utils.py b/school/lms/utils.py index 1eae98e7..8f2356fe 100644 --- a/school/lms/utils.py +++ b/school/lms/utils.py @@ -3,6 +3,7 @@ import frappe from frappe.utils import flt, cint, cstr from school.lms.md import markdown_to_html import string +from frappe import _ RE_SLUG_NOTALLOWED = re.compile("[^a-z0-9]+") @@ -296,3 +297,30 @@ def is_instructor(course): def convert_number_to_character(number): return string.ascii_uppercase[number] + +def get_signup_optin_checks(): + + mapper = frappe._dict({ + "terms_of_use": { + "page_name": "terms_page", + "title": _("Terms of Use") + }, + "privacy_policy": { + "page_name": "privacy_policy_page", + "title": _("Privacy Policy") + }, + "cookie_policy": { + "page_name": "cookie_policy_page", + "title": _("Cookie Policy") + } + }) + checks = ["terms_of_use", "privacy_policy", "cookie_policy"] + links = [] + + for check in checks: + if frappe.db.get_single_value("LMS Settings", check): + page = frappe.db.get_single_value("LMS Settings", mapper[check].get("page_name")) + route = frappe.db.get_value("Web Page", page, "route") + links.append("" + mapper[check].get("title") + "") + + return (", ").join(links) diff --git a/school/templates/signup-form.html b/school/templates/signup-form.html index 91c77910..1c668757 100644 --- a/school/templates/signup-form.html +++ b/school/templates/signup-form.html @@ -10,24 +10,6 @@
- {% set terms_of_use = frappe.db.get_single_value("LMS Settings", "terms_of_use") %} - {% set privacy_policy = frappe.db.get_single_value("LMS Settings", "privacy_policy") %} - - {% if terms_of_use or privacy_policy %} - - {% if terms_of_use %} - {% set terms_page = frappe.db.get_single_value("LMS Settings", "terms_page") %} - {% set terms_page_route = frappe.db.get_value("Web Page", terms_page, "route") %} - {% set terms_link = "" + _("Terms of Use") + "" %} - {% endif %} - - {% if privacy_policy %} - {% set privacy_policy_page = frappe.db.get_single_value("LMS Settings", "privacy_policy_page") %} - {% set privacy_page_route = frappe.db.get_value("Web Page", privacy_policy_page, "route") %} - {% set privacy_link = "" + _("Privacy Policy") + "" %} - {% endif %} - - {% set final_link = terms_link + _(" and ") + privacy_link if terms_of_use and privacy_policy else terms_link if terms_of_use else privacy_link %}
@@ -37,13 +19,12 @@ data-fieldtype="Check" data-fieldname="terms" id="signup-terms" required> - {{ _("I have read and agree to your {0}").format(final_link) }} + {{ _("I have read and agree to your {0}").format(get_signup_optin_checks()) }}

- {% endif %}