From a6156ec863b37d29063ac29d8babe23e64432027 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 26 Sep 2022 22:09:18 +0530 Subject: [PATCH] feat: get notifications --- lms/lms/widgets/CourseCard.html | 20 +++++------ lms/www/dashboard/index.html | 14 +++++++- lms/www/dashboard/index.py | 59 +++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 11 deletions(-) diff --git a/lms/lms/widgets/CourseCard.html b/lms/lms/widgets/CourseCard.html index c84ab45d..11af8e13 100644 --- a/lms/lms/widgets/CourseCard.html +++ b/lms/lms/widgets/CourseCard.html @@ -2,17 +2,17 @@ {% set progress = frappe.utils.cint(membership.progress) %}
-
-
- {% for tag in get_tags(course.name) %} -
{{ tag }}
- {% endfor %} +
+
+ {% for tag in get_tags(course.name) %} +
{{ tag }}
+ {% endfor %} +
+ {% if not course.image %} +
{{ course.title[0] }}
+ {% endif %}
- {% if not course.image %} -
{{ course.title[0] }}
- {% endif %} -
diff --git a/lms/www/dashboard/index.html b/lms/www/dashboard/index.html index cd2d8df1..ad6e894b 100644 --- a/lms/www/dashboard/index.html +++ b/lms/www/dashboard/index.html @@ -62,7 +62,19 @@ {% endif %}
- {% include "lms/templates/courses_created.html" %} + {% if notifications | length %} + {% for notification in notifications %} + {{ notification }} + {% endfor %} + {% else %} +
+ +
+
{{ _("No Notifications") }}
+
{{ _("You don't have any notifications.") }}
+
+
+ {% endif %}
diff --git a/lms/www/dashboard/index.py b/lms/www/dashboard/index.py index 68951425..674da52d 100644 --- a/lms/www/dashboard/index.py +++ b/lms/www/dashboard/index.py @@ -1,4 +1,5 @@ import frappe +from datetime import datetime from lms.lms.utils import has_course_instructor_role, has_course_moderator_role @@ -7,3 +8,61 @@ def get_context(context): portal_course_creation = frappe.db.get_single_value("LMS Settings", "portal_course_creation") context.show_creators_section = portal_course_creation == "Anyone" or has_course_instructor_role() context.show_review_section = has_course_moderator_role() + context.notifications = get_notifications() + + +def get_notifications(): + notifications = [] + + notifications += get_notifications_from_lessons_created() + + notifications += get_notifications_from_topics_created() + + if len(notifications): + print(notifications) + notifications = sorted(notifications, key=lambda t: datetime.strptime(frappe.utils.format_datetime(t.creation, "dd-mm-yyyy HH:mm:ss"),"%d/%m/%Y %H:%M:%S")) + return notifications + + +def get_notifications_from_lessons_created(): + + lessons = frappe.get_all("Course Lesson", { + "owner": frappe.session.user + }, ["name"]) + + for lesson in lessons: + topics = frappe.get_all("Discussion Topic", { + "reference_doctype": "Course Lesson", + "reference_docname": lesson.name + }, ["name"]) + + return get_notifications_from_replies(topics) + + +def get_notifications_from_topics_created(): + + topics = frappe.get_all("Discussion Topic", { + "owner": frappe.session.user + }, ["name"]) + + return get_notifications_from_replies(topics) + + + +def get_notifications_from_replies(topics): + notifications = [] + + for topic in topics: + replies = frappe.get_all("Discussion Reply", { + "topic": topic.name + }, ["reply", "owner", "creation"]) + + + for reply in replies: + notification = frappe._dict() + notification["message"] = reply.reply + notification["user"] = reply.owner + notification["creation"] = reply.creation + notifications.append(notification) + + return notifications