Merge pull request #725 from pateljannat/students-in-batch

feat: self enrolment in batches
This commit is contained in:
Jannat Patel
2024-01-22 10:54:20 +05:30
committed by GitHub
5 changed files with 48 additions and 2 deletions

View File

@@ -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)

View File

@@ -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-22 10:42:42.872995",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Batch",

View File

@@ -146,6 +146,10 @@
href="/billing/batch/{{ batch_info.name }}">
{{ _("Register Now") }}
</a>
{% elif batch_info.allow_self_enrollment %}
<button class="btn btn-primary wide-button enroll-batch">
{{ _("Enroll Now") }}
</button>
{% else %}
<div class="alert alert-info">
{{ _("To join this batch, please contact the Administrator.") }}

View File

@@ -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",

View File

@@ -35,6 +35,7 @@ def get_context(context):
"batch_details_raw",
"evaluation_end_date",
"amount_usd",
"allow_self_enrollment",
],
as_dict=1,
)