diff --git a/frontend/src/pages/Batch.vue b/frontend/src/pages/Batch.vue index ef38c899..401fdb6b 100644 --- a/frontend/src/pages/Batch.vue +++ b/frontend/src/pages/Batch.vue @@ -313,7 +313,7 @@ const tabs = computed(() => { }) const redirectToLogin = () => { - window.location.href = `/login?redirect-to=/batches` + window.location.href = `/login?redirect-to=/lms/batch/${props.batchName}` } const openAnnouncementModal = () => { diff --git a/lms/hooks.py b/lms/hooks.py index e1ec5c55..999ba199 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -116,6 +116,8 @@ scheduler_events = { "daily": [ "lms.job.doctype.job_opportunity.job_opportunity.update_job_openings", "lms.lms.doctype.lms_payment.lms_payment.send_payment_reminder", + "lms.lms.doctype.lms_batch.lms_batch.send_batch_start_reminder", + "lms.lms.doctype.lms_live_class.lms_live_class.send_live_class_reminder", ], } diff --git a/lms/lms/doctype/lms_batch/lms_batch.py b/lms/lms/doctype/lms_batch/lms_batch.py index 22a0c2f6..71aa9c94 100644 --- a/lms/lms/doctype/lms_batch/lms_batch.py +++ b/lms/lms/doctype/lms_batch/lms_batch.py @@ -8,7 +8,7 @@ import json from frappe import _ from datetime import timedelta from frappe.model.document import Document -from frappe.utils import cint, format_datetime, get_time +from frappe.utils import cint, format_datetime, get_time, add_days, nowdate from lms.lms.utils import ( get_lessons, get_lesson_index, @@ -405,3 +405,40 @@ def is_milestone_complete(idx, batch): return False return True + + +def send_batch_start_reminder(): + batches = frappe.get_all( + "LMS Batch", + {"start_date": add_days(nowdate(), 1), "published": 1}, + ["name", "title", "start_date", "start_time", "medium"], + ) + + for batch in batches: + students = frappe.get_all( + "LMS Batch Enrollment", {"batch": batch}, ["member", "member_name"] + ) + for student in students: + send_mail(batch, student) + + +def send_mail(batch, student): + subject = _("Batch Start Reminder") + template = "batch_start_reminder" + + args = { + "student_name": student.member_name, + "title": batch.title, + "start_date": batch.start_date, + "start_time": batch.start_time, + "medium": batch.medium, + "name": batch.name, + } + + frappe.sendmail( + recipients=student.member, + subject=subject, + template=template, + args=args, + header=[_(f"Batch Start Reminder: {batch.title}"), "orange"], + ) diff --git a/lms/lms/doctype/lms_batch_enrollment/lms_batch_enrollment.py b/lms/lms/doctype/lms_batch_enrollment/lms_batch_enrollment.py index 8de7715e..8fd3124c 100644 --- a/lms/lms/doctype/lms_batch_enrollment/lms_batch_enrollment.py +++ b/lms/lms/doctype/lms_batch_enrollment/lms_batch_enrollment.py @@ -79,20 +79,13 @@ def send_mail(doc): batch = frappe.db.get_value( "LMS Batch", doc.batch, - [ - "name", - "title", - "start_date", - "start_time", - "medium", - "confirmation_email_template", - ], + ["name", "title", "start_date", "start_time", "medium"], as_dict=1, ) subject = _("Enrollment Confirmation for {0}").format(batch.title) template = "batch_confirmation" - custom_template = batch.confirmation_email_template or frappe.db.get_single_value( + custom_template = frappe.db.get_single_value( "LMS Settings", "batch_confirmation_template" ) diff --git a/lms/lms/doctype/lms_live_class/lms_live_class.py b/lms/lms/doctype/lms_live_class/lms_live_class.py index a86676d3..8251e3c4 100644 --- a/lms/lms/doctype/lms_live_class/lms_live_class.py +++ b/lms/lms/doctype/lms_live_class/lms_live_class.py @@ -2,9 +2,10 @@ # For license information, please see license.txt import frappe +from frappe import _ from frappe.model.document import Document from datetime import timedelta -from frappe.utils import cint, get_datetime +from frappe.utils import cint, get_datetime, format_date, nowdate, format_time class LMSLiveClass(Document): @@ -56,8 +57,48 @@ class LMSLiveClass(Document): { "sync_with_google_calendar": 1, "google_calendar": calendar, - "description": f"A Live Class has been scheduled on {frappe.utils.format_date(self.date, 'medium')} at { frappe.utils.format_time(self.time, 'hh:mm a')}. Click on this link to join. {self.join_url}. {self.description}", + "description": f"A Live Class has been scheduled on {format_date(self.date, 'medium')} at {format_time(self.time, 'hh:mm a')}. Click on this link to join. {self.join_url}. {self.description}", } ) event.save() + + +def send_live_class_reminder(): + classes = frappe.get_all( + "LMS Live Class", + { + "date": nowdate(), + }, + ["name", "batch_name", "title", "date", "time"], + ) + + for live_class in classes: + students = frappe.get_all( + "LMS Batch Enrollment", + {"batch": live_class.batch_name}, + ["member", "member_name"], + ) + for student in students: + send_mail(live_class, student) + + +def send_mail(live_class, student): + subject = f"Your class on {live_class.title} is tomorrow" + template = "live_class_reminder" + + args = { + "student_name": student.member_name, + "title": live_class.title, + "date": live_class.date, + "time": live_class.time, + "batch_name": live_class.batch_name, + } + + frappe.sendmail( + recipients=student.member, + subject=subject, + template=template, + args=args, + header=[_(f"Class Reminder: {live_class.title}"), "orange"], + ) diff --git a/lms/templates/emails/batch_start_reminder.html b/lms/templates/emails/batch_start_reminder.html new file mode 100644 index 00000000..bd98170c --- /dev/null +++ b/lms/templates/emails/batch_start_reminder.html @@ -0,0 +1,35 @@ +

+ {{ _("Dear ") }} {{ student_name }}, +

+
+

+ {{ _("The batch you have enrolled for is starting tomorrow. Please be prepared and be on time for the session.") }} +

+
+

+ {{ _("Batch:") }} {{ title }} +

+
+

+ {{ _("Start Date:") }} {{ frappe.utils.format_date(start_date, "medium") }} +

+
+

+ {{ _("Timings:") }} {{ frappe.utils.format_time(start_time, "hh:mm a") }} +

+
+

+ {{ _("Medium:") }} {{ medium }} +

+
+

+ {{ _("Visit the following link to view your ") }} + {{ _("Batch Details") }} +

+

+ {{ _("If you have any questions or require assistance, feel free to contact us.") }} +

+
+

+ {{ _("Best Regards") }} +

diff --git a/lms/templates/emails/live_class_reminder.html b/lms/templates/emails/live_class_reminder.html new file mode 100644 index 00000000..6081c15c --- /dev/null +++ b/lms/templates/emails/live_class_reminder.html @@ -0,0 +1,31 @@ +

+ {{ _("Dear ") }} {{ student_name }}, +

+
+

+ {{ _("You have a live class scheduled tomorrow. Please be prepared and be on time for the session.") }} +

+
+

+ {{ _("Class:") }} {{ title }} +

+
+

+ {{ _("Date:") }} {{ frappe.utils.format_date(date, "medium") }} +

+
+

+ {{ _("Timings:") }} {{ frappe.utils.format_time(time, "hh:mm a") }} +

+
+

+ {{ _("Visit the following link to view your ") }} + {{ _("Batch Details") }} +

+

+ {{ _("If you have any questions or require assistance, feel free to contact us.") }} +

+
+

+ {{ _("Best Regards") }} +

\ No newline at end of file