From b70dfc8e82b9d3d8b4eebb422e935447e8324c33 Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Fri, 17 Nov 2023 10:45:29 +0530
Subject: [PATCH 01/10] fix: upcoming batches based on start time
---
lms/lms/doctype/lms_batch/lms_batch.json | 8 +++++---
lms/public/js/common_functions.js | 2 ++
lms/www/batches/index.html | 12 ++++++++++++
lms/www/batches/index.py | 10 ++++++++--
4 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/lms/lms/doctype/lms_batch/lms_batch.json b/lms/lms/doctype/lms_batch/lms_batch.json
index f0838a4b..c5c66723 100644
--- a/lms/lms/doctype/lms_batch/lms_batch.json
+++ b/lms/lms/doctype/lms_batch/lms_batch.json
@@ -120,12 +120,14 @@
{
"fieldname": "start_time",
"fieldtype": "Time",
- "label": "Start Time"
+ "label": "Start Time",
+ "reqd": 1
},
{
"fieldname": "end_time",
"fieldtype": "Time",
- "label": "End Time"
+ "label": "End Time",
+ "reqd": 1
},
{
"fieldname": "assessment_tab",
@@ -281,7 +283,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2023-10-12 12:53:37.351989",
+ "modified": "2023-11-17 10:41:00.340418",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Batch",
diff --git a/lms/public/js/common_functions.js b/lms/public/js/common_functions.js
index e4cf8433..88a86e28 100644
--- a/lms/public/js/common_functions.js
+++ b/lms/public/js/common_functions.js
@@ -308,12 +308,14 @@ const open_batch_dialog = () => {
label: __("Start Time"),
fieldname: "start_time",
default: batch_info && batch_info.start_time,
+ reqd: 1,
},
{
fieldtype: "Time",
label: __("End Time"),
fieldname: "end_time",
default: batch_info && batch_info.end_time,
+ reqd: 1,
},
{
fieldtype: "Link",
diff --git a/lms/www/batches/index.html b/lms/www/batches/index.html
index d05bf6f5..0e18eb46 100644
--- a/lms/www/batches/index.html
+++ b/lms/www/batches/index.html
@@ -147,6 +147,18 @@
+
+
+
+
+
+ {{ frappe.utils.format_time(batch.start_time, "HH:mm a") }} -
+
+
+ {{ frappe.utils.format_time(batch.end_time, "HH:mm a") }}
+
+
+
diff --git a/lms/www/batches/index.py b/lms/www/batches/index.py
index 6112fdc2..127fe5f2 100644
--- a/lms/www/batches/index.py
+++ b/lms/www/batches/index.py
@@ -1,5 +1,5 @@
import frappe
-from frappe.utils import getdate
+from frappe.utils import getdate, get_time_str, nowtime
from lms.lms.utils import (
has_course_moderator_role,
has_course_evaluator_role,
@@ -19,6 +19,8 @@ def get_context(context):
"description",
"start_date",
"end_date",
+ "start_time",
+ "end_time",
"paid_batch",
"amount",
"currency",
@@ -43,7 +45,11 @@ def get_context(context):
)
if not batch.published:
private_batches.append(batch)
- elif getdate(batch.start_date) <= getdate():
+ elif getdate(batch.start_date) < getdate():
+ past_batches.append(batch)
+ elif (
+ getdate(batch.start_date) == getdate() and get_time_str(batch.start_time) < nowtime()
+ ):
past_batches.append(batch)
else:
upcoming_batches.append(batch)
From 8cdaa7877aa58640f3f40db78a7012b3f9207821 Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Tue, 21 Nov 2023 13:32:12 +0530
Subject: [PATCH 02/10] feat: discussions mention notifications
---
lms/hooks.py | 8 +-
lms/lms/doctype/lms_batch/lms_batch.py | 1 -
lms/lms/utils.py | 91 +++++++++++++++++++++-
lms/templates/emails/mention_template.html | 11 +++
4 files changed, 103 insertions(+), 8 deletions(-)
create mode 100644 lms/templates/emails/mention_template.html
diff --git a/lms/hooks.py b/lms/hooks.py
index dbfd815f..7b819d16 100644
--- a/lms/hooks.py
+++ b/lms/hooks.py
@@ -97,7 +97,7 @@ override_doctype_class = {
# 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
@@ -118,9 +118,9 @@ fixtures = ["Custom Field", "Function", "Industry"]
# 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,
diff --git a/lms/lms/doctype/lms_batch/lms_batch.py b/lms/lms/doctype/lms_batch/lms_batch.py
index cf371f55..9f96d4cd 100644
--- a/lms/lms/doctype/lms_batch/lms_batch.py
+++ b/lms/lms/doctype/lms_batch/lms_batch.py
@@ -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
diff --git a/lms/lms/utils.py b/lms/lms/utils.py
index 3ed651e4..a60c5126 100644
--- a/lms/lms/utils.py
+++ b/lms/lms/utils.py
@@ -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,
@@ -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":
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"
@@ -640,6 +650,40 @@ def create_notification_log(doc, method):
make_notification_logs(notification, users)
+def notify_mentions(doc, topic):
+ mentions = extract_mentions(doc.reply)
+ print(mentions)
+ 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"
+
+ args = {
+ "sender": sender_fullname,
+ "content": doc.reply,
+ "batch_link": "/batches/" + topic.reference_docname,
+ }
+ 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"])
@@ -1092,3 +1136,44 @@ def change_currency(amount, currency, country=None):
amount = cint(amount)
amount, currency = check_multicurrency(amount, currency, country)
return fmt_money(amount, 0, currency)
+
+
+@frappe.whitelist()
+def get_names_for_mentions(search_term):
+ print(search_term)
+ users_for_mentions = frappe.cache.get_value(
+ "users_for_mentions", get_users_for_mentions
+ )
+ print(users_for_mentions)
+ user_groups = frappe.cache.get_value("user_groups", get_user_groups)
+
+ filtered_mentions = []
+ for mention_data in users_for_mentions + user_groups:
+ if search_term.lower() not in mention_data.value.lower():
+ continue
+
+ mention_data["link"] = frappe.utils.get_url_to_form(
+ "User Group" if mention_data.get("is_group") else "User Profile", mention_data["id"]
+ )
+
+ filtered_mentions.append(mention_data)
+
+ return sorted(filtered_mentions, key=lambda d: d["value"])
+
+
+def get_users_for_mentions():
+ print("this.is.users")
+ filters = (
+ {
+ "name": ["not in", ("Administrator", "Guest")],
+ "allowed_in_mentions": True,
+ "enabled": True,
+ },
+ )
+ print(frappe.utils.get_url())
+ print("this.is.url")
+ return frappe.get_all(
+ "User",
+ filters=filters,
+ fields=["name as id", "full_name as value", "user_type"],
+ )
diff --git a/lms/templates/emails/mention_template.html b/lms/templates/emails/mention_template.html
new file mode 100644
index 00000000..ed0ecc4b
--- /dev/null
+++ b/lms/templates/emails/mention_template.html
@@ -0,0 +1,11 @@
+
+ {{ _("{0} mentioned you in a comment in your batch.").format(sender) }}
+
+
+
+ {{ content | markdown }}
+
+
+
\ No newline at end of file
From 2388b878dc16b296f99a8c02afe327917803668b Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Tue, 21 Nov 2023 13:35:47 +0530
Subject: [PATCH 03/10] fix: encode chapter during lesson creation
---
lms/www/batch/edit.html | 2 +-
lms/www/batch/edit.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lms/www/batch/edit.html b/lms/www/batch/edit.html
index 312e060f..b75ddbe1 100644
--- a/lms/www/batch/edit.html
+++ b/lms/www/batch/edit.html
@@ -70,7 +70,7 @@
{{ _("Title") }}
-
+
diff --git a/lms/www/batch/edit.js b/lms/www/batch/edit.js
index 13010356..d9e2d892 100644
--- a/lms/www/batch/edit.js
+++ b/lms/www/batch/edit.js
@@ -234,7 +234,7 @@ const save = () => {
args: {
title: $("#lesson-title").val(),
body: this.lesson_content_data,
- chapter: $("#lesson-title").data("chapter"),
+ chapter: decodeURIComponent($("#lesson-title").data("chapter")),
preview: $("#preview").prop("checked") ? 1 : 0,
idx: $("#lesson-title").data("index"),
lesson: lesson ? lesson : "",
From 6da0c07a3d4992602a614a32a5cbbcd0e71cbd12 Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Tue, 21 Nov 2023 14:13:11 +0530
Subject: [PATCH 04/10] fix: course creation issue
---
lms/lms/utils.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lms/lms/utils.py b/lms/lms/utils.py
index 3ed651e4..ccf3a6f4 100644
--- a/lms/lms/utils.py
+++ b/lms/lms/utils.py
@@ -548,6 +548,9 @@ def can_create_courses(course, member=None):
if portal_course_creation == "Anyone" and member in instructors:
return True
+ if not course and has_course_instructor_role(member):
+ return True
+
return False
From 81db6c544d904cd273a28f7ab02a53251087e3c1 Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Wed, 22 Nov 2023 13:04:04 +0530
Subject: [PATCH 05/10] fix: mention email link
---
lms/hooks.py | 2 +-
lms/lms/utils.py | 47 +++--------------------------------------------
2 files changed, 4 insertions(+), 45 deletions(-)
diff --git a/lms/hooks.py b/lms/hooks.py
index 7b819d16..0e2b3adf 100644
--- a/lms/hooks.py
+++ b/lms/hooks.py
@@ -119,7 +119,7 @@ fixtures = ["Custom Field", "Function", "Industry"]
# ------------------------------
#
override_whitelisted_methods = {
- "frappe.desk.search.get_names_for_mentions": "lms.lms.utils.get_names_for_mentions",
+ # "frappe.desk.search.get_names_for_mentions": "lms.lms.utils.get_names_for_mentions",
}
#
# each overriding function accepts a `data` argument;
diff --git a/lms/lms/utils.py b/lms/lms/utils.py
index a60c5126..473066b4 100644
--- a/lms/lms/utils.py
+++ b/lms/lms/utils.py
@@ -617,7 +617,7 @@ def handle_notifications(doc, method):
["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)
@@ -652,7 +652,6 @@ def create_notification_log(doc, topic):
def notify_mentions(doc, topic):
mentions = extract_mentions(doc.reply)
- print(mentions)
if not mentions:
return
@@ -671,8 +670,9 @@ def notify_mentions(doc, topic):
args = {
"sender": sender_fullname,
"content": doc.reply,
- "batch_link": "/batches/" + topic.reference_docname,
+ "batch_link": "/batches/" + topic.reference_docname + "#discussions",
}
+
for recipient in recipients:
frappe.sendmail(
recipients=recipient,
@@ -1136,44 +1136,3 @@ def change_currency(amount, currency, country=None):
amount = cint(amount)
amount, currency = check_multicurrency(amount, currency, country)
return fmt_money(amount, 0, currency)
-
-
-@frappe.whitelist()
-def get_names_for_mentions(search_term):
- print(search_term)
- users_for_mentions = frappe.cache.get_value(
- "users_for_mentions", get_users_for_mentions
- )
- print(users_for_mentions)
- user_groups = frappe.cache.get_value("user_groups", get_user_groups)
-
- filtered_mentions = []
- for mention_data in users_for_mentions + user_groups:
- if search_term.lower() not in mention_data.value.lower():
- continue
-
- mention_data["link"] = frappe.utils.get_url_to_form(
- "User Group" if mention_data.get("is_group") else "User Profile", mention_data["id"]
- )
-
- filtered_mentions.append(mention_data)
-
- return sorted(filtered_mentions, key=lambda d: d["value"])
-
-
-def get_users_for_mentions():
- print("this.is.users")
- filters = (
- {
- "name": ["not in", ("Administrator", "Guest")],
- "allowed_in_mentions": True,
- "enabled": True,
- },
- )
- print(frappe.utils.get_url())
- print("this.is.url")
- return frappe.get_all(
- "User",
- filters=filters,
- fields=["name as id", "full_name as value", "user_type"],
- )
From 6f40c357b31774d30fc89f44017703730826ba13 Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Wed, 22 Nov 2023 17:27:42 +0530
Subject: [PATCH 06/10] fix: quiz submission page rendering
---
lms/lms/doctype/lms_payment/lms_payment.js | 16 ++++++----
lms/lms/doctype/lms_quiz/lms_quiz.py | 1 +
lms/lms/utils.py | 9 +++++-
lms/templates/emails/mention_template.html | 2 +-
lms/templates/quiz/quiz.html | 3 --
lms/templates/quiz/quiz.js | 3 ++
lms/www/quiz_submission/quiz_submission.py | 34 +++++++++++++++++++++-
7 files changed, 57 insertions(+), 11 deletions(-)
diff --git a/lms/lms/doctype/lms_payment/lms_payment.js b/lms/lms/doctype/lms_payment/lms_payment.js
index 11d42cab..b2d03500 100644
--- a/lms/lms/doctype/lms_payment/lms_payment.js
+++ b/lms/lms/doctype/lms_payment/lms_payment.js
@@ -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,
+ },
+ };
+ });
+ },
+});
diff --git a/lms/lms/doctype/lms_quiz/lms_quiz.py b/lms/lms/doctype/lms_quiz/lms_quiz.py
index 709cfe34..bbaaabb7 100644
--- a/lms/lms/doctype/lms_quiz/lms_quiz.py
+++ b/lms/lms/doctype/lms_quiz/lms_quiz.py
@@ -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,
}
diff --git a/lms/lms/utils.py b/lms/lms/utils.py
index 473066b4..70f186fc 100644
--- a/lms/lms/utils.py
+++ b/lms/lms/utils.py
@@ -667,10 +667,17 @@ def notify_mentions(doc, topic):
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,
- "batch_link": "/batches/" + topic.reference_docname + "#discussions",
+ "link": link,
}
for recipient in recipients:
diff --git a/lms/templates/emails/mention_template.html b/lms/templates/emails/mention_template.html
index ed0ecc4b..f791df47 100644
--- a/lms/templates/emails/mention_template.html
+++ b/lms/templates/emails/mention_template.html
@@ -7,5 +7,5 @@
\ No newline at end of file
diff --git a/lms/templates/quiz/quiz.html b/lms/templates/quiz/quiz.html
index 84caaf50..ccbdc9d1 100644
--- a/lms/templates/quiz/quiz.html
+++ b/lms/templates/quiz/quiz.html
@@ -10,9 +10,6 @@
{{ _("You will have to get {0}% correct answers in order to pass the quiz.").format(quiz.passing_percentage) }}
-
- {{ _("Without passing the quiz you won't be able to complete the lesson.") }}
-
{% endif %}
{% if quiz.max_attempts %}
diff --git a/lms/templates/quiz/quiz.js b/lms/templates/quiz/quiz.js
index ed37a030..186ba447 100644
--- a/lms/templates/quiz/quiz.js
+++ b/lms/templates/quiz/quiz.js
@@ -134,6 +134,9 @@ const quiz_summary = (e = undefined) => {
$(".quiz-footer span").addClass("hide");
$("#quiz-form").prepend(
`
+ ${__("You got")} ${data.message.percentage}% ${__("correct answers")}
+
+
${__("Your score is")} ${data.message.score}
${__("out of")} ${data.message.score_out_of}
`
diff --git a/lms/www/quiz_submission/quiz_submission.py b/lms/www/quiz_submission/quiz_submission.py
index f7d3f35b..6f6292c4 100644
--- a/lms/www/quiz_submission/quiz_submission.py
+++ b/lms/www/quiz_submission/quiz_submission.py
@@ -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()
From a17a7453e7bec56f729bea7a59e1bad63751f6ec Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Wed, 22 Nov 2023 17:49:47 +0530
Subject: [PATCH 07/10] fix: ceil the percentage
---
lms/templates/quiz/quiz.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lms/templates/quiz/quiz.js b/lms/templates/quiz/quiz.js
index 186ba447..3491c5e4 100644
--- a/lms/templates/quiz/quiz.js
+++ b/lms/templates/quiz/quiz.js
@@ -134,7 +134,7 @@ const quiz_summary = (e = undefined) => {
$(".quiz-footer span").addClass("hide");
$("#quiz-form").prepend(
`
- ${__("You got")} ${data.message.percentage}% ${__("correct answers")}
+ ${__("You got")} ${Math.ceil(data.message.percentage)}% ${__("correct answers")}
${__("Your score is")} ${data.message.score}
From ddcb718a3ac4303a5bd0e201c16b67adabd638cd Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Thu, 23 Nov 2023 11:50:22 +0530
Subject: [PATCH 08/10] fix: quiz submission questions
---
lms/lms/doctype/lms_quiz/lms_quiz.py | 2 +-
lms/templates/quiz/quiz.js | 11 +++++------
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/lms/lms/doctype/lms_quiz/lms_quiz.py b/lms/lms/doctype/lms_quiz/lms_quiz.py
index bbaaabb7..80f0ab46 100644
--- a/lms/lms/doctype/lms_quiz/lms_quiz.py
+++ b/lms/lms/doctype/lms_quiz/lms_quiz.py
@@ -69,7 +69,7 @@ def quiz_summary(quiz, results):
question_details = frappe.db.get_value(
"LMS Quiz Question",
- {"parent": quiz, "idx": result["question_index"] + 1},
+ {"parent": quiz, "idx": result["question_index"]},
["question", "marks"],
as_dict=1,
)
diff --git a/lms/templates/quiz/quiz.js b/lms/templates/quiz/quiz.js
index 3491c5e4..3a86aa7b 100644
--- a/lms/templates/quiz/quiz.js
+++ b/lms/templates/quiz/quiz.js
@@ -4,6 +4,7 @@ frappe.ready(() => {
this.answer = [];
this.is_correct = [];
this.show_answers = $("#quiz-title").data("show-answers");
+ this.current_index = 0;
localStorage.removeItem($("#quiz-title").data("name"));
$(".btn-start-quiz").click((e) => {
@@ -37,7 +38,6 @@ frappe.ready(() => {
$("#next").click((e) => {
e.preventDefault();
if (!this.show_answers) check_answer();
-
mark_active_question(e);
});
@@ -48,7 +48,7 @@ frappe.ready(() => {
const mark_active_question = (e = undefined) => {
let total_questions = $(".question").length;
- let current_index = $(".active-question").attr("data-qt-index") || 0;
+ let current_index = this.current_index;
let next_index = parseInt(current_index) + 1;
if (this.show_answers) {
@@ -170,7 +170,7 @@ const check_answer = (e = undefined) => {
e && e.preventDefault();
let answer = $(".active-question textarea");
let total_questions = $(".question").length;
- let current_index = $(".active-question").attr("data-qt-index");
+ let current_index = this.current_index;
if (answer.length && !answer.val().trim()) {
frappe.throw(__("Please enter your answer"));
@@ -188,6 +188,7 @@ const check_answer = (e = undefined) => {
$("#next").removeClass("hide");
}
parse_options();
+ this.current_index += 1;
};
const parse_options = () => {
@@ -277,12 +278,10 @@ const add_icon = (element, icon) => {
};
const add_to_local_storage = () => {
- let current_index = $(".active-question").attr("data-qt-index");
let quiz_name = $("#quiz-title").data("name");
let quiz_stored = JSON.parse(localStorage.getItem(quiz_name));
-
let quiz_obj = {
- question_index: current_index - 1,
+ question_index: this.current_index,
answer: self.answer.join(),
is_correct: self.is_correct,
};
From fd9a63887940dae67f170da5e3edd931eb344e40 Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Fri, 24 Nov 2023 12:37:34 +0530
Subject: [PATCH 09/10] fix: quiz and timetable issues
---
lms/templates/quiz/quiz.js | 2 +-
lms/www/batches/batch.js | 12 +++++++---
lms/www/quiz_submission/quiz_submission.py | 26 +++++++++++-----------
3 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/lms/templates/quiz/quiz.js b/lms/templates/quiz/quiz.js
index 3a86aa7b..d7b891b6 100644
--- a/lms/templates/quiz/quiz.js
+++ b/lms/templates/quiz/quiz.js
@@ -182,7 +182,7 @@ const check_answer = (e = undefined) => {
$(".explanation").removeClass("hide");
$("#check").addClass("hide");
- if (current_index == total_questions) {
+ if (current_index == total_questions - 1) {
$("#summary").removeClass("hide");
} else if (this.show_answers) {
$("#next").removeClass("hide");
diff --git a/lms/www/batches/batch.js b/lms/www/batches/batch.js
index 111c1307..cf81c223 100644
--- a/lms/www/batches/batch.js
+++ b/lms/www/batches/batch.js
@@ -658,7 +658,7 @@ const setup_calendar = (events) => {
const calendar = new Calendar(container, options);
this.calendar_ = calendar;
- create_events(calendar, events);
+ create_events(calendar, events, calendar_id);
add_links_to_events(calendar, events);
scroll_to_date(calendar, events);
set_calendar_range(calendar, events);
@@ -710,8 +710,8 @@ const create_events = (calendar, events, calendar_id) => {
id: `event${idx}`,
calendarId: calendar_id,
title: event.title,
- start: `${event.date}T${event.start_time}`,
- end: `${event.date}T${event.end_time}`,
+ start: `${event.date}T${format_time(event.start_time)}`,
+ end: `${event.date}T${format_time(event.end_time)}`,
isAllday: event.start_time ? false : true,
borderColor: clr,
backgroundColor: "var(--fg-color)",
@@ -735,6 +735,12 @@ const create_events = (calendar, events, calendar_id) => {
calendar.createEvents(calendar_events);
};
+const format_time = (time) => {
+ let time_arr = time.split(":");
+ if (time_arr[0] < 10) time_arr[0] = "0" + time_arr[0];
+ return time_arr.join(":");
+};
+
const add_links_to_events = (calendar) => {
calendar.on("clickEvent", ({ event }) => {
let event_date = event.start.d.d;
diff --git a/lms/www/quiz_submission/quiz_submission.py b/lms/www/quiz_submission/quiz_submission.py
index 6f6292c4..719d5886 100644
--- a/lms/www/quiz_submission/quiz_submission.py
+++ b/lms/www/quiz_submission/quiz_submission.py
@@ -47,9 +47,20 @@ def get_context(context):
quiz.questions.append(details)
context.quiz = quiz
+ context.all_submissions = frappe.get_all(
+ "LMS Quiz Submission",
+ {
+ "quiz": context.quiz.name,
+ "member": frappe.session.user,
+ },
+ ["name", "score", "creation"],
+ order_by="creation desc",
+ )
+
+ context.no_of_attempts = len(context.all_submissions) or 0
+
if submission == "new-submission":
context.submission = frappe._dict()
- context.no_of_attempts = 0
context.hide_quiz = False
else:
context.submission = frappe.db.get_value(
@@ -65,17 +76,6 @@ def get_context(context):
if not context.quiz or not context.submission:
raise frappe.PermissionError(_("Invalid Submission URL"))
- context.all_submissions = frappe.get_all(
- "LMS Quiz Submission",
- {
- "quiz": context.quiz.name,
- "member": context.submission.member,
- },
- ["name", "score", "creation"],
- order_by="creation desc",
- )
-
- context.no_of_attempts = len(context.all_submissions) or 0
context.hide_quiz = (
- context.is_moderator and context.submission.member != frappe.session.user
+ context.is_moderator or context.submission.member != frappe.session.user
)
From de60fbb25a44965728118feed9247d31e5c73a3e Mon Sep 17 00:00:00 2001
From: Md Hussain Nagaria <34810212+NagariaHussain@users.noreply.github.com>
Date: Mon, 27 Nov 2023 22:19:07 +0530
Subject: [PATCH 10/10] fix(LMS Batch): add portal web link to form view (#692)
---
lms/lms/doctype/lms_batch/lms_batch.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lms/lms/doctype/lms_batch/lms_batch.js b/lms/lms/doctype/lms_batch/lms_batch.js
index 34f9d503..9f6b23ab 100644
--- a/lms/lms/doctype/lms_batch/lms_batch.js
+++ b/lms/lms/doctype/lms_batch/lms_batch.js
@@ -33,6 +33,10 @@ frappe.ui.form.on("LMS Batch", {
timetable_template: function (frm) {
set_timetable(frm);
},
+
+ refresh: (frm) => {
+ frm.add_web_link(`/batches/details/${frm.doc.name}`, "See on website");
+ },
});
const set_timetable = (frm) => {