From 5e569ab0e6d8b03a3a441cb19542f9f429929227 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 19 Jan 2024 23:56:48 +0530 Subject: [PATCH] feat: self enrollment in batches --- .../doctype/batch_student/batch_student.py | 12 +++++++++- lms/lms/doctype/lms_batch/lms_batch.json | 18 +++++++++++++- lms/www/batches/batch_details.html | 4 ++++ lms/www/batches/batch_details.js | 24 +++++++++++++++++++ lms/www/batches/batch_details.py | 1 + 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/lms/lms/doctype/batch_student/batch_student.py b/lms/lms/doctype/batch_student/batch_student.py index 7cd9a61a..d3168f71 100644 --- a/lms/lms/doctype/batch_student/batch_student.py +++ b/lms/lms/doctype/batch_student/batch_student.py @@ -1,9 +1,19 @@ # Copyright (c) 2022, Frappe and contributors # For license information, please see license.txt -# import frappe +import frappe from frappe.model.document import Document class BatchStudent(Document): pass + + +@frappe.whitelist() +def enroll_batch(batch_name): + enrollment = frappe.new_doc("Batch Student") + enrollment.student = frappe.session.user + enrollment.parent = batch_name + enrollment.parentfield = "students" + enrollment.parenttype = "LMS Batch" + enrollment.save(ignore_permissions=True) diff --git a/lms/lms/doctype/lms_batch/lms_batch.json b/lms/lms/doctype/lms_batch/lms_batch.json index b05ee563..48d2e0c8 100644 --- a/lms/lms/doctype/lms_batch/lms_batch.json +++ b/lms/lms/doctype/lms_batch/lms_batch.json @@ -15,6 +15,7 @@ "start_time", "end_time", "published", + "allow_self_enrollment", "section_break_rgfj", "medium", "category", @@ -293,11 +294,17 @@ "fieldname": "amount_usd", "fieldtype": "Currency", "label": "Amount (USD)" + }, + { + "default": "0", + "fieldname": "allow_self_enrollment", + "fieldtype": "Check", + "label": "Allow Self Enrollment" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-12-21 12:27:16.849362", + "modified": "2024-01-19 23:36:17.351413", "modified_by": "Administrator", "module": "LMS", "name": "LMS Batch", @@ -327,6 +334,15 @@ "role": "Moderator", "share": 1, "write": 1 + }, + { + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "LMS Student", + "share": 1 } ], "show_title_field_in_link": 1, diff --git a/lms/www/batches/batch_details.html b/lms/www/batches/batch_details.html index 9fd5c93e..7c5b5123 100644 --- a/lms/www/batches/batch_details.html +++ b/lms/www/batches/batch_details.html @@ -146,6 +146,10 @@ href="/billing/batch/{{ batch_info.name }}"> {{ _("Register Now") }} + {% elif batch_info.allow_self_enrollment %} + {% else %}
{{ _("To join this batch, please contact the Administrator.") }} diff --git a/lms/www/batches/batch_details.js b/lms/www/batches/batch_details.js index 92070ece..865fbcd6 100644 --- a/lms/www/batches/batch_details.js +++ b/lms/www/batches/batch_details.js @@ -12,6 +12,10 @@ frappe.ready(() => { $(".btn-remove-course").click((e) => { remove_course(e); }); + + $(".enroll-batch").click((e) => { + enroll_batch(e); + }); }); const show_course_modal = (e) => { @@ -54,6 +58,26 @@ const show_course_modal = (e) => { }, 1000); }; +const enroll_batch = (e) => { + let batch_name = $(".class-details").data("batch"); + frappe.call({ + method: "lms.lms.doctype.batch_student.batch_student.enroll_batch", + args: { + batch_name: batch_name, + }, + callback(r) { + frappe.show_alert( + { + message: __("Successfully Enrolled"), + indicator: "green", + }, + 2000 + ); + window.location.href = `/batches/${batch_name}`; + }, + }); +}; + const add_course = (values, course_name) => { frappe.call({ method: "lms.lms.doctype.lms_batch.lms_batch.add_course", diff --git a/lms/www/batches/batch_details.py b/lms/www/batches/batch_details.py index fdeb035b..97f950d9 100644 --- a/lms/www/batches/batch_details.py +++ b/lms/www/batches/batch_details.py @@ -35,6 +35,7 @@ def get_context(context): "batch_details_raw", "evaluation_end_date", "amount_usd", + "allow_self_enrollment", ], as_dict=1, )