refactor: added question type field

This commit is contained in:
Shivam Mishra 2019-05-30 18:54:58 +05:30
parent 253a2bd260
commit 7c7053fcf5
2 changed files with 75 additions and 154 deletions

View File

@ -1,167 +1,80 @@
{ {
"allow_copy": 0, "allow_import": 1,
"allow_events_in_timeline": 0, "autoname": "format:QUESTION-{#####}",
"allow_guest_to_view": 0, "creation": "2018-10-01 15:58:00.696815",
"allow_import": 1, "doctype": "DocType",
"allow_rename": 0, "editable_grid": 1,
"autoname": "format:QUESTION-{#####}", "engine": "InnoDB",
"beta": 0, "field_order": [
"creation": "2018-10-01 15:58:00.696815", "question",
"custom": 0, "options",
"docstatus": 0, "question_type"
"doctype": "DocType", ],
"document_type": "",
"editable_grid": 1,
"engine": "InnoDB",
"fields": [ "fields": [
{ {
"allow_bulk_edit": 0, "fieldname": "question",
"allow_in_quick_entry": 0, "fieldtype": "Small Text",
"allow_on_submit": 0, "in_list_view": 1,
"bold": 0, "label": "Question",
"collapsible": 0, "reqd": 1
"columns": 0, },
"fetch_if_empty": 0,
"fieldname": "question",
"fieldtype": "Small Text",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Question",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "fieldname": "options",
"allow_in_quick_entry": 0, "fieldtype": "Table",
"allow_on_submit": 0, "label": "Options",
"bold": 0, "options": "Options",
"collapsible": 0, "reqd": 1
"columns": 0, },
"description": "", {
"fetch_if_empty": 0, "fieldname": "question_type",
"fieldname": "options", "fieldtype": "Select",
"fieldtype": "Table", "in_standard_filter": 1,
"hidden": 0, "label": "Type",
"ignore_user_permissions": 0, "options": "\nSingle Correct Answer\nMultiple Correct Answer",
"ignore_xss_filter": 0, "read_only": 1
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Options",
"length": 0,
"no_copy": 0,
"options": "Options",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
} }
], ],
"has_web_view": 0, "modified": "2019-05-30 18:39:21.880974",
"hide_toolbar": 0, "modified_by": "Administrator",
"idx": 0, "module": "Education",
"in_create": 0, "name": "Question",
"is_submittable": 0, "owner": "Administrator",
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2019-04-22 14:02:08.140652",
"modified_by": "Administrator",
"module": "Education",
"name": "Question",
"name_case": "",
"owner": "Administrator",
"permissions": [ "permissions": [
{ {
"amend": 0, "create": 1,
"cancel": 0, "delete": 1,
"create": 1, "email": 1,
"delete": 1, "export": 1,
"email": 1, "print": 1,
"export": 1, "read": 1,
"if_owner": 0, "report": 1,
"import": 0, "role": "Academics User",
"permlevel": 0, "share": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Academics User",
"set_user_permissions": 0,
"share": 1,
"submit": 0,
"write": 1 "write": 1
}, },
{ {
"amend": 0, "create": 1,
"cancel": 0, "delete": 1,
"create": 1, "email": 1,
"delete": 1, "export": 1,
"email": 1, "print": 1,
"export": 1, "read": 1,
"if_owner": 0, "report": 1,
"import": 0, "role": "Instructor",
"permlevel": 0, "share": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Instructor",
"set_user_permissions": 0,
"share": 1,
"submit": 0,
"write": 1 "write": 1
}, },
{ {
"amend": 0, "email": 1,
"cancel": 0, "export": 1,
"create": 0, "print": 1,
"delete": 0, "read": 1,
"email": 1, "report": 1,
"export": 1, "role": "LMS User",
"if_owner": 0, "share": 1
"import": 0,
"permlevel": 0,
"print": 1,
"read": 1,
"report": 1,
"role": "LMS User",
"set_user_permissions": 0,
"share": 1,
"submit": 0,
"write": 0
} }
], ],
"quick_entry": 1, "quick_entry": 1,
"read_only": 0, "sort_field": "modified",
"show_name_in_global_search": 0, "sort_order": "DESC"
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 0,
"track_seen": 0,
"track_views": 0
} }

View File

@ -12,6 +12,7 @@ class Question(Document):
def validate(self): def validate(self):
self.check_at_least_one_option() self.check_at_least_one_option()
self.check_minimum_one_correct_answer() self.check_minimum_one_correct_answer()
self.set_question_type()
def check_at_least_one_option(self): def check_at_least_one_option(self):
if len(self.options) <= 1: if len(self.options) <= 1:
@ -26,6 +27,13 @@ class Question(Document):
else: else:
frappe.throw(_("A qustion must have at least one correct options")) frappe.throw(_("A qustion must have at least one correct options"))
def set_question_type(self):
correct_options = [option for option in self.options if option.is_correct]
if len(correct_options) > 1:
self.question_type = "Multiple Correct Answer"
else:
self.question_type = "Single Correct Answer"
def get_answer(self): def get_answer(self):
options = self.options options = self.options
answers = [item.name for item in options if item.is_correct == True] answers = [item.name for item in options if item.is_correct == True]