Merge pull request #681 from pateljannat/notify-mentions

feat: misc changes
This commit is contained in:
Jannat Patel
2023-11-22 17:34:44 +05:30
committed by GitHub
9 changed files with 118 additions and 18 deletions

View File

@@ -64,7 +64,6 @@ class LMSBatch(Document):
def send_confirmation_mail(self):
for student in self.students:
if not student.confirmation_email_sent:
self.send_mail(student)
student.confirmation_email_sent = 1

View File

@@ -1,8 +1,14 @@
// Copyright (c) 2023, Frappe and contributors
// For license information, please see license.txt
// frappe.ui.form.on("LMS Payment", {
// refresh(frm) {
// },
// });
frappe.ui.form.on("LMS Payment", {
onload(frm) {
frm.set_query("member", function (doc) {
return {
filters: {
ignore_user_type: 1,
},
};
});
},
});

View File

@@ -110,6 +110,7 @@ def quiz_summary(quiz, results):
"score_out_of": score_out_of,
"submission": submission.name,
"pass": percentage == quiz_details.passing_percentage,
"percentage": percentage,
}

View File

@@ -6,7 +6,14 @@ import razorpay
import requests
from frappe import _
from frappe.desk.doctype.dashboard_chart.dashboard_chart import get_result
from frappe.desk.doctype.notification_log.notification_log import make_notification_logs
from frappe.desk.doctype.notification_log.notification_log import (
make_notification_logs,
enqueue_create_notification,
get_title,
)
from frappe.utils import get_fullname
from frappe.desk.search import get_user_groups
from frappe.desk.notifications import extract_mentions
from frappe.utils import (
add_months,
cint,
@@ -606,17 +613,20 @@ def validate_image(path):
return path
def create_notification_log(doc, method):
def handle_notifications(doc, method):
topic = frappe.db.get_value(
"Discussion Topic",
doc.topic,
["reference_doctype", "reference_docname", "owner", "title"],
as_dict=1,
)
if topic.reference_doctype != "Course Lesson":
if topic.reference_doctype not in ["Course Lesson", "LMS Batch"]:
return
create_notification_log(doc, topic)
notify_mentions(doc, topic)
def create_notification_log(doc, topic):
course = frappe.db.get_value("Course Lesson", topic.reference_docname, "course")
instructors = frappe.db.get_all(
"Course Instructor", {"parent": course}, pluck="instructor"
@@ -643,6 +653,47 @@ def create_notification_log(doc, method):
make_notification_logs(notification, users)
def notify_mentions(doc, topic):
mentions = extract_mentions(doc.reply)
if not mentions:
return
sender_fullname = get_fullname(doc.owner)
recipients = [
frappe.db.get_value(
"User",
{"enabled": 1, "name": name},
"email",
)
for name in mentions
]
subject = _("{0} mentioned you in a comment").format(sender_fullname)
template = "mention_template"
if topic.reference_doctype == "LMS Batch":
link = f"/batches/{topic.reference_docname}#discussions"
if topic.reference_doctype == "Course Lesson":
course = frappe.db.get_value("Course Lesson", topic.reference_docname, "course")
lesson_index = get_lesson_index(topic.reference_docname)
link = get_lesson_url(course, lesson_index)
args = {
"sender": sender_fullname,
"content": doc.reply,
"link": link,
}
for recipient in recipients:
frappe.sendmail(
recipients=recipient,
subject=subject,
template=template,
args=args,
header=[subject, "green"],
retry=3,
)
def get_lesson_count(course):
lesson_count = 0
chapters = frappe.get_all("Chapter Reference", {"parent": course}, ["chapter"])