diff -r 0b57494e8b4e -r 8ca2734bdc99 quiz/management/commands/seed_que.py --- a/quiz/management/commands/seed_que.py Tue Jun 29 11:38:04 2010 +0530 +++ b/quiz/management/commands/seed_que.py Tue Jun 29 11:47:53 2010 +0530 @@ -2,21 +2,27 @@ from django.core.management.base import NoArgsCommand -from offline.quiz.models import QuestionBank, Quiz +from offline.quiz.models import QuestionBank, Quiz, TOPIC_CHOICES name2num = {"day1quiz1" : "11", "day1quiz2" : "12", "day2quiz1" : "21", } +topic_name2num = dict( [ (_[1], _[0]) for _ in TOPIC_CHOICES ] ) + def seed_que(): for question in QuestionBank.objects.all(): question.delete() q_bank = parse("question_bank.xml").getElementsByTagName("question") for question in q_bank: - quiz_name = question.parentNode.tagName - quiz_num = name2num[quiz_name] + #quiz_name = question.parentNode.tagName + #quiz_num = name2num[quiz_name] + + topic_name_node = question.getElementsByTagName("topic")[0] + topic_name = (topic_name_node.childNodes[0].data).strip() + topic = topic_name2num[topic_name] description_node = question.getElementsByTagName("description")[0] description = (description_node.childNodes[0].data).strip() @@ -24,7 +30,6 @@ time_limit_node = question.getElementsByTagName("time_limit")[0] time_limit = time_limit_node.childNodes[0].data - options_nodes = question.getElementsByTagName("options") options = (options_nodes[0].childNodes[0].data).strip() if options_nodes else "" @@ -34,7 +39,7 @@ expected_ans_node = question.getElementsByTagName("expected_answer")[0] expected_ans = (expected_ans_node.childNodes[0].data).strip() - new_question = QuestionBank(quiz_num = quiz_num, + new_question = QuestionBank(topic = topic, description = description, time_limit = time_limit, options = options,