From 6dd68e4c896a14f71a58b2745d983c3a4b25e326 Mon Sep 17 00:00:00 2001 From: Ebuka Date: Sun, 10 Dec 2023 14:54:54 +0100 Subject: [PATCH 1/2] Update LMS Doctype Changes --- one_lms/www/batch/learn.py | 2 +- one_lms/www/classes/class.html | 2 +- one_lms/www/classes/class.js | 10 +++++----- one_lms/www/classes/class.py | 8 ++++---- one_lms/www/classes/index.html | 4 ++-- one_lms/www/classes/index.py | 10 +++++----- one_lms/www/classes/progress.py | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/one_lms/www/batch/learn.py b/one_lms/www/batch/learn.py index 89a8710..c2f183a 100644 --- a/one_lms/www/batch/learn.py +++ b/one_lms/www/batch/learn.py @@ -51,7 +51,7 @@ def get_context(context): context.class_info = frappe._dict( { "name": class_name, - "title": frappe.db.get_value("LMS Class", class_name, "title"), + "title": frappe.db.get_value("LMS Batch", class_name, "title"), } ) diff --git a/one_lms/www/classes/class.html b/one_lms/www/classes/class.html index 8726da4..188cdf3 100644 --- a/one_lms/www/classes/class.html +++ b/one_lms/www/classes/class.html @@ -227,7 +227,7 @@ {% macro Discussions(class_info) %}
{% set condition = is_moderator or is_student or is_evaluator %} - {% set doctype, docname = _("LMS Class"), class_info.name %} + {% set doctype, docname = _("LMS Batch"), class_info.name %} {% set single_thread = True %} {% set title = "Discussions" %} {% set cta_title = "Post" %} diff --git a/one_lms/www/classes/class.js b/one_lms/www/classes/class.js index 7b43379..bea3012 100644 --- a/one_lms/www/classes/class.js +++ b/one_lms/www/classes/class.js @@ -327,9 +327,9 @@ const add_course = (values) => { method: "frappe.client.insert", args: { doc: { - doctype: "Class Course", + doctype: "Batch Course", course: values.course, - parenttype: "LMS Class", + parenttype: "LMS Batch", parentfield: "courses", parent: $(".class-details").data("class"), }, @@ -402,9 +402,9 @@ const add_student = (values) => { method: "frappe.client.insert", args: { doc: { - doctype: "Class Student", + doctype: "Batch Student", student: values.student, - parenttype: "LMS Class", + parenttype: "LMS Batch", parentfield: "students", parent: $(".class-details").data("class"), }, @@ -513,7 +513,7 @@ const add_addessment = (values) => { doctype: "LMS Assessment", assessment_type: values.assessment_type, assessment_name: values.assessment_name, - parenttype: "LMS Class", + parenttype: "LMS Batch", parentfield: "assessment", parent: $(".class-details").data("class"), }, diff --git a/one_lms/www/classes/class.py b/one_lms/www/classes/class.py index e1b862e..0e134df 100644 --- a/one_lms/www/classes/class.py +++ b/one_lms/www/classes/class.py @@ -22,7 +22,7 @@ def get_context(context): context.is_evaluator = has_course_evaluator_role() context.class_info = frappe.db.get_value( - "LMS Class", + "LMS Batch", class_name, [ "name", @@ -40,18 +40,18 @@ def get_context(context): as_dict=True, ) - context.reference_doctype = "LMS Class" + context.reference_doctype = "LMS Batch" context.reference_name = class_name class_courses = frappe.get_all( - "Class Course", + "Batch Course", {"parent": class_name}, ["name", "course", "title"], order_by="creation desc", ) class_students = frappe.get_all( - "Class Student", + "Batch Student", {"parent": class_name}, ["name", "student", "student_name", "username"], order_by="creation desc", diff --git a/one_lms/www/classes/index.html b/one_lms/www/classes/index.html index 081c8b0..6f0b938 100644 --- a/one_lms/www/classes/index.html +++ b/one_lms/www/classes/index.html @@ -90,8 +90,8 @@ {% macro ClassCards(classes) %}
{% for class in classes %} - {% set course_count = frappe.db.count("Class Course", {"parent": class.name}) %} - {% set student_count = frappe.db.count("Class Student", {"parent": class.name}) %} + {% set course_count = frappe.db.count("Batch Course", {"parent": class.name}) %} + {% set student_count = frappe.db.count("Batch Student", {"parent": class.name}) %}
diff --git a/one_lms/www/classes/index.py b/one_lms/www/classes/index.py index 4c0c83f..943f91a 100644 --- a/one_lms/www/classes/index.py +++ b/one_lms/www/classes/index.py @@ -7,14 +7,14 @@ def get_context(context): context.no_cache = 1 context.is_moderator = has_course_moderator_role() classes = frappe.get_all( - "LMS Class", + "LMS Batch", fields=[ "name", "title", "description", "start_date", "end_date", - "paid_class", + "paid_batch", "seat_count", ], ) @@ -32,15 +32,15 @@ def get_context(context): if frappe.session.user != "Guest": my_classes_info = [] my_classes = frappe.get_all( - "Class Student", {"student": frappe.session.user}, pluck="parent" + "Batch Student", {"student": frappe.session.user}, pluck="parent" ) for class_ in my_classes: my_classes_info.append( frappe.db.get_value( - "LMS Class", + "LMS Batch", class_, - ["name", "title", "start_date", "end_date", "paid_class", "seat_count"], + ["name", "title", "start_date", "end_date", "paid_batch", "seat_count"], as_dict=True, ) ) diff --git a/one_lms/www/classes/progress.py b/one_lms/www/classes/progress.py index 90b4128..d7121be 100644 --- a/one_lms/www/classes/progress.py +++ b/one_lms/www/classes/progress.py @@ -30,11 +30,11 @@ def get_context(context): raise frappe.PermissionError(_("You don't have permission to access this page.")) context.class_info = frappe.db.get_value( - "LMS Class", class_name, ["name"], as_dict=True + "LMS Batch", class_name, ["name"], as_dict=True ) context.courses = frappe.get_all( - "Class Course", {"parent": class_name}, pluck="course" + "Batch Course", {"parent": class_name}, pluck="course" ) context.assessments = get_assessments(class_name, context.student.name) From 095903b9a8e5ee948831a03d1575cdfa85f76fc0 Mon Sep 17 00:00:00 2001 From: Ebuka Date: Tue, 12 Dec 2023 10:17:29 +0100 Subject: [PATCH 2/2] Update can create course function in one lms --- one_lms/www/assignments/assignment.py | 6 ++++-- one_lms/www/batch/quiz.py | 17 +++++++++++++---- one_lms/www/batch/quiz_list.py | 4 ++-- one_lms/www/courses/course.py | 2 +- one_lms/www/courses/outline.py | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/one_lms/www/assignments/assignment.py b/one_lms/www/assignments/assignment.py index 9b1c299..ded9b7c 100644 --- a/one_lms/www/assignments/assignment.py +++ b/one_lms/www/assignments/assignment.py @@ -1,12 +1,13 @@ import frappe from frappe import _ -from lms.lms.utils import can_create_courses +from lms.lms.utils import has_course_moderator_role, has_course_instructor_role + def get_context(context): context.no_cache = 1 - if not can_create_courses(): + if not has_course_moderator_role() or not has_course_instructor_role(): message = "You do not have permission to access this page." if frappe.session.user == "Guest": message = "Please login to access this page." @@ -21,3 +22,4 @@ def get_context(context): context.assignment = frappe.db.get_value( "LMS Assignment", assignment, ["title", "name", "type", "question"], as_dict=1 ) + diff --git a/one_lms/www/batch/quiz.py b/one_lms/www/batch/quiz.py index f88aaef..4ecf5c4 100644 --- a/one_lms/www/batch/quiz.py +++ b/one_lms/www/batch/quiz.py @@ -1,13 +1,13 @@ import frappe from frappe.utils import cstr from frappe import _ -from lms.lms.utils import can_create_courses +from lms.lms.utils import has_course_instructor_role, has_course_moderator_role def get_context(context): context.no_cache = 1 - if not can_create_courses(): + if not has_course_moderator_role() or not has_course_instructor_role(): message = "You do not have permission to access this page." if frappe.session.user == "Guest": message = "Please login to access this page." @@ -18,14 +18,23 @@ def get_context(context): if quizname == "new-quiz": context.quiz = frappe._dict() else: - fields_arr = ["name", "question", "type"] context.quiz = frappe.db.get_value( "LMS Quiz", quizname, - ["title", "name", "max_attempts", "show_answers", "show_submission_history"], + [ + "title", + "name", + "max_attempts", + "passing_percentage", + "show_answers", + "show_submission_history", + ], as_dict=1, ) + + fields_arr = ["name", "question", "marks"] context.quiz.questions = frappe.get_all( "LMS Quiz Question", {"parent": quizname}, fields_arr, order_by="idx" ) + diff --git a/one_lms/www/batch/quiz_list.py b/one_lms/www/batch/quiz_list.py index ae8df7f..ee4321a 100644 --- a/one_lms/www/batch/quiz_list.py +++ b/one_lms/www/batch/quiz_list.py @@ -1,12 +1,12 @@ import frappe -from lms.lms.utils import can_create_courses, has_course_moderator_role +from lms.lms.utils import has_course_instructor_role, has_course_moderator_role from frappe import _ def get_context(context): context.no_cache = 1 - if not can_create_courses(): + if not has_course_moderator_role() or not has_course_instructor_role(): message = "You do not have permission to access this page." if frappe.session.user == "Guest": message = "Please login to access this page." diff --git a/one_lms/www/courses/course.py b/one_lms/www/courses/course.py index 6ed9ab4..d5077f2 100644 --- a/one_lms/www/courses/course.py +++ b/one_lms/www/courses/course.py @@ -22,7 +22,7 @@ def get_context(context): redirect_to_courses_list() if course_name == "new-course": - if not can_create_courses(): + if not can_create_courses(course_name): message = "You do not have permission to access this page." if frappe.session.user == "Guest": message = "Please login to access this page." diff --git a/one_lms/www/courses/outline.py b/one_lms/www/courses/outline.py index ad8f18d..f01a71a 100644 --- a/one_lms/www/courses/outline.py +++ b/one_lms/www/courses/outline.py @@ -10,7 +10,7 @@ def get_context(context): if not frappe.db.exists("LMS Course", course_name): redirect_to_courses_list() - if not can_create_courses(): + if not can_create_courses(course_name): message = "You do not have permission to access this page." if frappe.session.user == "Guest": message = "Please login to access this page."