feat: get notifications
This commit is contained in:
@@ -2,17 +2,17 @@
|
||||
{% set progress = frappe.utils.cint(membership.progress) %}
|
||||
<div class="common-card-style course-card" data-course="{{ course.name }}">
|
||||
|
||||
<div class="course-image {% if not course.image %}default-image{% endif %}" {% if course.image %}
|
||||
style="background-image: url( {{ course.image | urlencode }} );" {% endif %}>
|
||||
<div class="course-tags">
|
||||
{% for tag in get_tags(course.name) %}
|
||||
<div class="course-card-pills">{{ tag }}</div>
|
||||
{% endfor %}
|
||||
<div class="course-image {% if not course.image %}default-image{% endif %}"
|
||||
{% if course.image %} style="background-image: url( {{ course.image | urlencode }} );" {% endif %}>
|
||||
<div class="course-tags">
|
||||
{% for tag in get_tags(course.name) %}
|
||||
<div class="course-card-pills">{{ tag }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if not course.image %}
|
||||
<div class="default-image-text">{{ course.title[0] }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if not course.image %}
|
||||
<div class="default-image-text">{{ course.title[0] }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="course-card-content">
|
||||
<div class="course-card-meta">
|
||||
|
||||
@@ -62,7 +62,19 @@
|
||||
{% endif %}
|
||||
|
||||
<div class="tab-pane fade" id="notifications" role="tabpanel" aria-labelledby="notifications">
|
||||
{% include "lms/templates/courses_created.html" %}
|
||||
{% if notifications | length %}
|
||||
{% for notification in notifications %}
|
||||
{{ notification }}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<img class="icon icon-xl" src="/assets/lms/icons/comment.svg">
|
||||
<div class="empty-state-text">
|
||||
<div class="empty-state-heading">{{ _("No Notifications") }}</div>
|
||||
<div class="course-meta">{{ _("You don't have any notifications.") }}</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user