Merge pull request #1316 from FahidLatheef/fix/quiz-maximum-attempts

fix: fixed bug in which user can submit quiz over the maximum limit allowed
This commit is contained in:
Jannat Patel
2025-02-17 19:59:57 +05:30
committed by GitHub
19 changed files with 62 additions and 21 deletions

View File

@@ -10,12 +10,29 @@ from frappe.desk.doctype.notification_log.notification_log import make_notificat
class LMSQuizSubmission(Document):
def validate(self):
self.validate_if_max_attempts_exceeded()
self.validate_marks()
self.set_percentage()
def on_update(self):
self.notify_member()
def validate_if_max_attempts_exceeded(self):
max_attempts = frappe.db.get_value("LMS Quiz", self.quiz, ["max_attempts"])
if max_attempts == 0:
return
current_user_submission_count = frappe.db.count(
self.doctype, filters={"quiz": self.quiz, "member": frappe.session.user}
)
if current_user_submission_count >= max_attempts:
frappe.throw(
_("You have exceeded the maximum number of attempts ({0}) for this quiz").format(
max_attempts
),
MaximumAttemptsExceededError,
)
def validate_marks(self):
self.score = 0
for row in self.result:
@@ -52,3 +69,7 @@ class LMSQuizSubmission(Document):
)
make_notification_logs(notification, [self.member])
class MaximumAttemptsExceededError(frappe.DuplicateEntryError):
pass

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr ""
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr ""
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr ""
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr ""
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr "Max. Versuche"
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr ""
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr "crwdns150150:0crwdne150150:0"
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr "crwdns150152:0crwdne150152:0"
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr "Intentos máximos"
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr "Intentos máximos"
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr ""
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr ""
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr ""
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr ""
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr ""
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr ""
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3042,7 +3042,7 @@ msgid "Max Attempts"
msgstr ""
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr ""
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr ""
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr ""
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr "Максимум попыток"
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr ""
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr "Maximalt antal försök"
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr "Maximalt antal försök"
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr "Maksimum Deneme"
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr ""
#. Label of the medium (Select) field in DocType 'LMS Batch'

View File

@@ -3031,7 +3031,7 @@ msgid "Max Attempts"
msgstr ""
#: frontend/src/pages/QuizForm.vue:58
msgid "Maximun Attempts"
msgid "Maximum Attempts"
msgstr ""
#. Label of the medium (Select) field in DocType 'LMS Batch'