1 from xml.dom.minidom import parse, Node |
1 from xml.dom.minidom import parse, Node |
2 |
2 |
3 from django.core.management.base import NoArgsCommand |
3 from django.core.management.base import NoArgsCommand |
4 |
4 |
5 from offline.quiz.models import QuestionBank, Quiz |
5 from offline.quiz.models import QuestionBank, Quiz, TOPIC_CHOICES |
6 |
6 |
7 name2num = {"day1quiz1" : "11", |
7 name2num = {"day1quiz1" : "11", |
8 "day1quiz2" : "12", |
8 "day1quiz2" : "12", |
9 "day2quiz1" : "21", |
9 "day2quiz1" : "21", |
10 } |
10 } |
|
11 |
|
12 topic_name2num = dict( [ (_[1], _[0]) for _ in TOPIC_CHOICES ] ) |
11 |
13 |
12 def seed_que(): |
14 def seed_que(): |
13 for question in QuestionBank.objects.all(): |
15 for question in QuestionBank.objects.all(): |
14 question.delete() |
16 question.delete() |
15 |
17 |
16 q_bank = parse("question_bank.xml").getElementsByTagName("question") |
18 q_bank = parse("question_bank.xml").getElementsByTagName("question") |
17 for question in q_bank: |
19 for question in q_bank: |
18 quiz_name = question.parentNode.tagName |
20 #quiz_name = question.parentNode.tagName |
19 quiz_num = name2num[quiz_name] |
21 #quiz_num = name2num[quiz_name] |
|
22 |
|
23 topic_name_node = question.getElementsByTagName("topic")[0] |
|
24 topic_name = (topic_name_node.childNodes[0].data).strip() |
|
25 topic = topic_name2num[topic_name] |
20 |
26 |
21 description_node = question.getElementsByTagName("description")[0] |
27 description_node = question.getElementsByTagName("description")[0] |
22 description = (description_node.childNodes[0].data).strip() |
28 description = (description_node.childNodes[0].data).strip() |
23 |
29 |
24 time_limit_node = question.getElementsByTagName("time_limit")[0] |
30 time_limit_node = question.getElementsByTagName("time_limit")[0] |
25 time_limit = time_limit_node.childNodes[0].data |
31 time_limit = time_limit_node.childNodes[0].data |
26 |
|
27 |
32 |
28 options_nodes = question.getElementsByTagName("options") |
33 options_nodes = question.getElementsByTagName("options") |
29 options = (options_nodes[0].childNodes[0].data).strip() if options_nodes else "" |
34 options = (options_nodes[0].childNodes[0].data).strip() if options_nodes else "" |
30 |
35 |
31 code_nodes = question.getElementsByTagName("code") |
36 code_nodes = question.getElementsByTagName("code") |
32 code = (code_nodes[0].childNodes[0].data).strip() if code_nodes else "" |
37 code = (code_nodes[0].childNodes[0].data).strip() if code_nodes else "" |
33 |
38 |
34 expected_ans_node = question.getElementsByTagName("expected_answer")[0] |
39 expected_ans_node = question.getElementsByTagName("expected_answer")[0] |
35 expected_ans = (expected_ans_node.childNodes[0].data).strip() |
40 expected_ans = (expected_ans_node.childNodes[0].data).strip() |
36 |
41 |
37 new_question = QuestionBank(quiz_num = quiz_num, |
42 new_question = QuestionBank(topic = topic, |
38 description = description, |
43 description = description, |
39 time_limit = time_limit, |
44 time_limit = time_limit, |
40 options = options, |
45 options = options, |
41 code = code, |
46 code = code, |
42 expected_ans = expected_ans, |
47 expected_ans = expected_ans, |