quiz/management/commands/seed_que.py
changeset 61 3b8b0ce51566
parent 60 8ca2734bdc99
equal deleted inserted replaced
60:8ca2734bdc99 61:3b8b0ce51566
     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, TOPIC_CHOICES
     5 from offline.quiz.models import QuestionBank, Quiz, TOPIC_CHOICES
     6 
       
     7 name2num = {"day1quiz1" : "11",
       
     8             "day1quiz2" : "12",
       
     9             "day2quiz1" : "21",
       
    10            }
       
    11 
     6 
    12 topic_name2num = dict( [ (_[1], _[0]) for _ in TOPIC_CHOICES ] )
     7 topic_name2num = dict( [ (_[1], _[0]) for _ in TOPIC_CHOICES ] )
    13 
     8 
    14 def seed_que():
     9 def seed_que():
    15     for question in QuestionBank.objects.all():
    10     for question in QuestionBank.objects.all():
    16         question.delete()
    11         question.delete()
    17 
    12 
    18     q_bank = parse("question_bank.xml").getElementsByTagName("question")
    13     q_bank = parse("question_bank.xml").getElementsByTagName("question")
       
    14 
    19     for question in q_bank:
    15     for question in q_bank:
    20         #quiz_name = question.parentNode.tagName
       
    21         #quiz_num = name2num[quiz_name]
       
    22 
    16 
    23         topic_name_node = question.getElementsByTagName("topic")[0]
    17         topic_name_node = question.getElementsByTagName("topic")[0]
    24         topic_name = (topic_name_node.childNodes[0].data).strip()
    18         topic_name = (topic_name_node.childNodes[0].data).strip()
    25         topic = topic_name2num[topic_name]
    19         topic = topic_name2num[topic_name]
    26 
    20