feat: notification sent checkbox to prevent resending the notification

This commit is contained in:
Jannat Patel
2026-01-13 19:06:30 +05:30
parent 8ad5288226
commit a09599ec8a
14 changed files with 437 additions and 526 deletions

View File

@@ -64,16 +64,15 @@ class LMSAssignmentSubmission(Document):
def trigger_update_notification(self):
notification = frappe._dict(
{
"subject": _("There has been an update on your submission for assignment {0}").format(
self.assignment_title
"subject": _("The instructor has left a comment on your assignment {0}").format(
frappe.bold(self.assignment_title)
),
"email_content": self.comments,
"document_type": self.doctype,
"document_name": self.name,
"for_user": self.owner,
"from_user": self.evaluator,
"type": "Alert",
"link": f"/assignment-submission/{self.assignment}/{self.name}",
"link": f"/lms/assignment-submission/{self.assignment}/{self.name}",
}
)
make_notification_logs(notification, [self.member])

View File

@@ -26,7 +26,6 @@
"description",
"column_break_hlqw",
"instructors",
"video_link",
"zoom_account",
"section_break_rgfj",
"medium",
@@ -35,6 +34,10 @@
"column_break_flwy",
"seat_count",
"evaluation_end_date",
"notification_sent",
"section_break_jedp",
"video_link",
"column_break_kpct",
"meta_image",
"section_break_khcn",
"batch_details",
@@ -367,6 +370,21 @@
"fieldname": "video_link",
"fieldtype": "Attach",
"label": "Preview Video"
},
{
"default": "0",
"fieldname": "notification_sent",
"fieldtype": "Check",
"label": "Notification Sent",
"read_only": 1
},
{
"fieldname": "section_break_jedp",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_kpct",
"fieldtype": "Column Break"
}
],
"grid_page_length": 50,
@@ -389,7 +407,7 @@
"link_fieldname": "payment_for_document"
}
],
"modified": "2026-01-06 18:54:22.216656",
"modified": "2026-01-13 18:50:27.420712",
"modified_by": "sayali@frappe.io",
"module": "LMS",
"name": "LMS Batch",

View File

@@ -136,6 +136,8 @@ def send_notification_for_published_batch(batch):
if not batch.published:
return
if batch.notification_sent:
return
if send_notification == "Email":
send_email_notification_for_published_batch(batch)
@@ -172,13 +174,7 @@ def send_email_notification_for_published_batch(batch):
template=template,
args=args,
)
""" frappe.sendmail(
recipients=["jannat@frappe.io"],
subject=subject,
template=template,
args=args,
) """
frappe.db.set_value("LMS Batch", batch.name, "notification_sent", 1)
def send_system_notification_for_published_batch(batch):
@@ -201,6 +197,7 @@ def send_system_notification_for_published_batch(batch):
}
)
make_notification_logs(notification, students)
frappe.db.set_value("LMS Batch", batch.name, "notification_sent", 1)
@frappe.whitelist()

View File

@@ -48,7 +48,8 @@
"statistics_section",
"enrollments",
"lessons",
"rating"
"rating",
"notification_sent"
],
"fields": [
{
@@ -288,6 +289,13 @@
"fieldname": "timezone",
"fieldtype": "Data",
"label": "Timezone"
},
{
"default": "0",
"fieldname": "notification_sent",
"fieldtype": "Check",
"label": "Notification Sent",
"read_only": 1
}
],
"is_published_field": "published",
@@ -306,7 +314,7 @@
}
],
"make_attachments_public": 1,
"modified": "2025-12-15 15:15:42.226098",
"modified": "2026-01-13 18:48:56.069280",
"modified_by": "sayali@frappe.io",
"module": "LMS",
"name": "LMS Course",

View File

@@ -142,6 +142,7 @@ def send_notification_for_published_courses():
"LMS Course",
{
"published_on": today(),
"notification_sent": 0,
},
["name", "title", "short_introduction"],
)
@@ -181,6 +182,7 @@ def send_email_notification_for_published_courses(courses):
template=template,
args=args,
)
frappe.db.set_value("LMS Course", course.name, "notification_sent", 1)
def send_system_notification_for_published_courses(courses):
@@ -204,3 +206,4 @@ def send_system_notification_for_published_courses(courses):
}
)
make_notification_logs(notification, students)
frappe.db.set_value("LMS Course", course.name, "notification_sent", 1)

View File

@@ -398,26 +398,47 @@ def handle_notifications(doc, method):
notify_mentions_via_email(doc, topic)
def create_notification_log(doc, topic):
def get_course_details_for_notification(topic):
users = []
course = frappe.db.get_value("Course Lesson", topic.reference_docname, "course")
course_title = frappe.db.get_value("LMS Course", course, "title")
instructors = frappe.db.get_all(
"Course Instructor", {"parent": course, "parenttype": "LMS Course"}, pluck="instructor"
)
users.append(topic.owner)
users += instructors
subject = _("New reply on the topic {0} in course {1}").format(topic.title, course_title)
link = get_lesson_url(course, get_lesson_index(topic.reference_docname))
return subject, link, users
def get_batch_details_for_notification(topic):
users = []
batch_title = frappe.db.get_value("LMS Batch", topic.reference_docname, "title")
subject = _("New comment in batch {0}").format(batch_title)
link = f"/lms/batches/{topic.reference_docname}"
instructors = frappe.db.get_all(
"Course Instructor",
{"parenttype": "LMS Batch", "parent": topic.reference_docname},
pluck="instructor",
)
students = frappe.db.get_all("LMS Batch Enrollment", {"batch": topic.reference_docname}, pluck="member")
users += instructors
users += students
return subject, link, users
def create_notification_log(doc, topic):
if topic.reference_doctype == "Course Lesson":
course = frappe.db.get_value("Course Lesson", topic.reference_docname, "course")
course_title = frappe.db.get_value("LMS Course", course, "title")
instructors = frappe.db.get_all("Course Instructor", {"parent": course}, pluck="instructor")
if doc.owner != topic.owner:
users.append(topic.owner)
users += instructors
subject = _("New reply on the topic {0} in course {1}").format(topic.title, course_title)
link = get_lesson_url(course, get_lesson_index(topic.reference_docname))
subject, link, users = get_course_details_for_notification(topic)
else:
batch_title = frappe.db.get_value("LMS Batch", topic.reference_docname, "title")
subject = _("New comment in batch {0}").format(batch_title)
link = f"/batches/{topic.reference_docname}"
moderators = frappe.get_all("Has Role", {"role": "Moderator"}, pluck="parent")
users += moderators
subject, link, users = get_batch_details_for_notification(topic)
if doc.owner in users:
users.remove(doc.owner)
notification = frappe._dict(
{
@@ -425,7 +446,6 @@ def create_notification_log(doc, topic):
"email_content": doc.reply,
"document_type": topic.reference_doctype,
"document_name": topic.reference_docname,
"for_user": topic.owner,
"from_user": doc.owner,
"type": "Alert",
"link": link,
@@ -453,7 +473,7 @@ def notify_mentions_on_portal(doc, topic):
subject = _("{0} mentioned you in a comment in {1}").format(
frappe.bold(from_user_name), frappe.bold(batch_title)
)
link = f"/lms/batches/{topic.reference_docname}"
link = f"/lms/batches/{topic.reference_docname}#discussions"
for user in mentions:
notification = frappe._dict(