Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: misc changes #681

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lms/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
# Hook on document methods and events

doc_events = {
"Discussion Reply": {"after_insert": "lms.lms.utils.create_notification_log"},
"Discussion Reply": {"after_insert": "lms.lms.utils.handle_notifications"},
}

# Scheduled Tasks
Expand All @@ -118,9 +118,9 @@
# Overriding Methods
# ------------------------------
#
# override_whitelisted_methods = {
# "frappe.desk.doctype.event.event.get_events": "lms.event.get_events"
# }
override_whitelisted_methods = {
# "frappe.desk.search.get_names_for_mentions": "lms.lms.utils.get_names_for_mentions",
}
#
# each overriding function accepts a `data` argument;
# generated from the base implementation of the doctype dashboard,
Expand Down
1 change: 0 additions & 1 deletion lms/lms/doctype/lms_batch/lms_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def validate_duplicate_assessments(self):

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
Expand Down
16 changes: 11 additions & 5 deletions lms/lms/doctype/lms_payment/lms_payment.js
Original file line number Diff line number Diff line change
@@ -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,
},
};
});
},
});
1 change: 1 addition & 0 deletions lms/lms/doctype/lms_quiz/lms_quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand Down
59 changes: 55 additions & 4 deletions lms/lms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
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,
Expand Down Expand Up @@ -603,17 +610,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"
Expand All @@ -640,6 +650,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"])
Expand Down
11 changes: 11 additions & 0 deletions lms/templates/emails/mention_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<p>
{{ _("{0} mentioned you in a comment in your batch.").format(sender) }}
</p>
<p>
<blockquote>
{{ content | markdown }}
</blockquote>
</p>
<div class="more-info">
<a href="{{ link }}">{{ _("Check Discussion") }}</a>
</div>
3 changes: 0 additions & 3 deletions lms/templates/quiz/quiz.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
<li>
{{ _("You will have to get {0}% correct answers in order to pass the quiz.").format(quiz.passing_percentage) }}
</li>
<li>
{{ _("Without passing the quiz you won't be able to complete the lesson.") }}
</li>
{% endif %}

{% if quiz.max_attempts %}
Expand Down
3 changes: 3 additions & 0 deletions lms/templates/quiz/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ const quiz_summary = (e = undefined) => {
$(".quiz-footer span").addClass("hide");
$("#quiz-form").prepend(
`<div class="summary bold-heading text-center">
${__("You got")} ${data.message.percentage}% ${__("correct answers")}
</div>
<div class="summary bold-heading text-center mt-2">
${__("Your score is")} ${data.message.score}
${__("out of")} ${data.message.score_out_of}
</div>`
Expand Down
34 changes: 33 additions & 1 deletion lms/www/quiz_submission/quiz_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,39 @@ def get_context(context):
submission = frappe.form_dict["submission"]
quiz_name = frappe.form_dict["quiz"]

context.quiz = frappe.get_doc("LMS Quiz", quiz_name)
quiz = frappe.db.get_value(
"LMS Quiz",
quiz_name,
[
"name",
"title",
"max_attempts",
"show_answers",
"show_submission_history",
"passing_percentage",
],
as_dict=True,
)
quiz.questions = []
fields = ["name", "question", "type", "multiple"]
for num in range(1, 5):
fields.append(f"option_{num}")
fields.append(f"is_correct_{num}")
fields.append(f"explanation_{num}")
fields.append(f"possibility_{num}")

questions = frappe.get_all(
"LMS Quiz Question",
filters={"parent": quiz.name},
fields=["question", "marks"],
order_by="idx",
)

for question in questions:
details = frappe.db.get_value("LMS Question", question.question, fields, as_dict=1)
details["marks"] = question.marks
quiz.questions.append(details)
context.quiz = quiz

if submission == "new-submission":
context.submission = frappe._dict()
Expand Down
Loading