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:
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user