diff --git a/frontend/src/pages/Notifications.vue b/frontend/src/pages/Notifications.vue
index afcfd9a5..525f091f 100644
--- a/frontend/src/pages/Notifications.vue
+++ b/frontend/src/pages/Notifications.vue
@@ -23,30 +23,71 @@
v-if="notifications?.length"
v-for="log in notifications"
:key="log.name"
- class="flex items-center py-2 justify-between"
+ class="flex space-x-2 p-2 rounded-md"
+ :class="{
+ 'cursor-pointer': log.link,
+ }"
+ @click="navigateToPage(log)"
>
-
-
@@ -57,11 +98,12 @@
-
diff --git a/lms/lms/api.py b/lms/lms/api.py
index dd43af53..0557c867 100644
--- a/lms/lms/api.py
+++ b/lms/lms/api.py
@@ -30,7 +30,13 @@ from frappe.utils import (
from frappe.utils.response import Response
from lms.lms.doctype.course_lesson.course_lesson import save_progress
-from lms.lms.utils import get_average_rating, get_batch_details, get_course_details, get_lesson_count
+from lms.lms.utils import (
+ get_average_rating,
+ get_batch_details,
+ get_course_details,
+ get_instructors,
+ get_lesson_count,
+)
@frappe.whitelist(allow_guest=True)
@@ -1232,19 +1238,36 @@ def get_notifications(filters):
notifications = frappe.get_all(
"Notification Log",
filters,
- ["subject", "from_user", "link", "read", "name"],
+ ["subject", "from_user", "link", "read", "name", "creation", "document_type", "document_name"],
order_by="creation desc",
)
for notification in notifications:
- from_user_details = frappe.db.get_value(
- "User", notification.from_user, ["full_name", "user_image"], as_dict=1
- )
- notification.update(from_user_details)
+ notification = update_user_details(notification)
+ notification = update_document_details(notification)
return notifications
+def update_user_details(notification):
+ from_user_details = frappe.db.get_value(
+ "User", notification.from_user, ["full_name", "user_image"], as_dict=1
+ )
+ notification.update(from_user_details)
+ return notification
+
+
+def update_document_details(notification):
+ if notification.document_type == "LMS Course":
+ details = frappe.db.get_value(
+ "LMS Course", notification.document_name, ["title", "video_link", "short_introduction"], as_dict=1
+ )
+ instructors = get_instructors("LMS Course", notification.document_name)
+ details["instructors"] = instructors
+ notification["document_details"] = details
+ return notification
+
+
@frappe.whitelist(allow_guest=True)
def get_lms_settings():
allowed_fields = [
diff --git a/lms/lms/doctype/lms_course/lms_course.py b/lms/lms/doctype/lms_course/lms_course.py
index e4aff90e..de5b40d9 100644
--- a/lms/lms/doctype/lms_course/lms_course.py
+++ b/lms/lms/doctype/lms_course/lms_course.py
@@ -2,12 +2,14 @@
# For license information, please see license.txt
import random
+
import frappe
from frappe import _
+from frappe.desk.doctype.notification_log.notification_log import make_notification_logs
from frappe.model.document import Document
from frappe.utils import cint, today
-from frappe.desk.doctype.notification_log.notification_log import make_notification_logs
-from ...utils import generate_slug, update_payment_record, validate_image
+
+from ...utils import generate_slug, get_instructors, update_payment_record, validate_image
class LMSCourse(Document):
@@ -130,14 +132,21 @@ class LMSCourse(Document):
def __repr__(self):
return f""
+
def send_notification_for_published_courses():
- send_notification_for_published_courses = frappe.db.get_single_value("LMS Settings", "send_notification_for_published_courses")
+ send_notification_for_published_courses = frappe.db.get_single_value(
+ "LMS Settings", "send_notification_for_published_courses"
+ )
if not send_notification_for_published_courses:
return
-
- courses_published_today = frappe.get_all("LMS Course", {
- "published_on": today(),
- }, ["name", "title", "video_link", "short_introduction"])
+
+ courses_published_today = frappe.get_all(
+ "LMS Course",
+ {
+ "published_on": today(),
+ },
+ ["name", "title", "video_link", "short_introduction"],
+ )
if not courses_published_today:
return
@@ -147,27 +156,24 @@ def send_notification_for_published_courses():
else:
send_system_notification_for_published_courses(courses_published_today)
+
def send_email_notification_for_published_courses(courses):
brand_name = frappe.db.get_single_value("Website Settings", "app_name")
brand_logo = frappe.db.get_single_value("Website Settings", "banner_image")
subject = _("A new course has been published on {0}").format(brand_name)
template = "published_course_notification"
- students = frappe.get_all("User", { "enabled": 1 }, pluck="name")
-
+ students = frappe.get_all("User", {"enabled": 1}, pluck="name")
+
for course in courses:
- instructor_details = []
- instructors = frappe.get_all("Course Instructor", { "parent": course.name }, pluck="instructor")
- for instructor in instructors:
- details = frappe.db.get_value("User", instructor, ["full_name", "email", "user_image"], as_dict=True)
- instructor_details.append(details)
-
+ instructors = get_instructors("LMS Course", course.name)
+
args = {
"brand_logo": brand_logo,
"brand_name": brand_name,
"preview_video": f"https://www.youtube.com/embed/{course.video_link}",
"title": course.title,
"short_introduction": course.short_introduction,
- "instructors": instructor_details,
+ "instructors": instructors,
"course_url": f"{frappe.utils.get_url()}/lms/courses/{course.name}",
}
@@ -179,17 +185,25 @@ def send_email_notification_for_published_courses(courses):
args=args,
)
+
def send_system_notification_for_published_courses(courses):
for course in courses:
- students = frappe.get_all("User", { "enabled": 1 }, pluck="name")
- instructors = frappe.get_all("Course Instructor", { "parent": course.name }, pluck="instructor")
- notification = frappe._dict({
- "subject": course.title,
- "email_content": _("A new course '{0}' has been published that might interest you. Check it out!").format(course.title),
- "document_type": "LMS Course",
- "document_name": course.name,
- "from_user": instructors[0] if instructors else None,
- "type": "Alert",
- "link": f"/lms/courses/{course.name}",
- })
- make_notification_logs(notification, ["ash@ipp.com"])
\ No newline at end of file
+ students = frappe.get_all("User", {"enabled": 1}, pluck="name")
+ instructors = frappe.get_all("Course Instructor", {"parent": course.name}, pluck="instructor")
+ instructor_name = frappe.db.get_value("User", instructors[0], "full_name")
+ notification = frappe._dict(
+ {
+ "subject": _("{0} has published a new course {1}").format(
+ frappe.bold(instructor_name), frappe.bold(course.title)
+ ),
+ "email_content": _(
+ "A new course '{0}' has been published that might interest you. Check it out!"
+ ).format(course.title),
+ "document_type": "LMS Course",
+ "document_name": course.name,
+ "from_user": instructors[0] if instructors else None,
+ "type": "Alert",
+ "link": f"/lms/courses/{course.name}",
+ }
+ )
+ make_notification_logs(notification, students)