feat: Added validations for question doctype
- A question must have more than two options - A question must have at least one correct option
This commit is contained in:
parent
5c646e60f5
commit
acc278de9c
@ -4,10 +4,28 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class Question(Document):
|
class Question(Document):
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
self.check_at_least_one_option()
|
||||||
|
self.check_minimum_one_correct_answer()
|
||||||
|
|
||||||
|
def check_at_least_one_option(self):
|
||||||
|
if len(self.get_all_children()) <= 1:
|
||||||
|
frappe.throw(_("A question must have more than one options"))
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def check_minimum_one_correct_answer(self):
|
||||||
|
correct_options = [question.is_correct for question in self.get_all_children()]
|
||||||
|
if bool(sum(correct_options)):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
frappe.throw(_("A qustion must have at least one correct options"))
|
||||||
|
|
||||||
def get_answer(self):
|
def get_answer(self):
|
||||||
options = self.get_all_children()
|
options = self.get_all_children()
|
||||||
answers = [item.name for item in options if item.is_correct == True]
|
answers = [item.name for item in options if item.is_correct == True]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user