# HG changeset patch # User nishanth # Date 1271828324 -19800 # Node ID 456b7b9e3d1375fcf424cb8e3f02e1620e6be763 # Parent 6233cf13fc126502a7217ffcc9df7bf1e3e98211 created a question bank xml file and created a seed_que command for adding questions to db from xml diff -r 6233cf13fc12 -r 456b7b9e3d13 question_bank.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/question_bank.xml Wed Apr 21 11:08:44 2010 +0530 @@ -0,0 +1,74 @@ + + + + + + How will you set the x and y axis limits so that the region of interest is in the rectangle $(0, -1.5)$ (left bottom coordinate) and $(2\pi, 1.5)$ (right top coordinate)? + + + 30 + + + xlim\( 0 , 2 \* pi \) [;,\n+] ylim\( -1.5 , 1.5\) + + + + + + If a = [1, 2, 5, 9] then what is the value of a[0:-1]? + + + 30 + + + \[ 1 , 2 , 5 \] + + + + + + A sample line from a Comma Separated Values (CSV) file: + line = "Rossum, Guido, 42, 56, 34, 54" + What code would you use to separate the line into fields? + + + 30 + + + (line\.split\( ([",']) , \2 \)) + + + + + + If a = [1, 2, 5, 9] how do you find the length of this list? + + + 30 + + + len\( a \) + + + + + + + + + What is the maximum number that can be represented natively in Python. + + + 30 + + + Infinite + 2**32 + + + 1 + + + + + diff -r 6233cf13fc12 -r 456b7b9e3d13 quiz/management/commands/seed_que.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/quiz/management/commands/seed_que.py Wed Apr 21 11:08:44 2010 +0530 @@ -0,0 +1,53 @@ +from xml.dom.minidom import parse, Node + +from django.core.management.base import NoArgsCommand + +from offline.quiz.models import QuestionBank + +name2num = {"day1quiz1" : "11", + "day1quiz2" : "12", + "day2quiz1" : "21", + } + +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] + + description_node = question.getElementsByTagName("description")[0] + description = (description_node.childNodes[0].data).strip() + + 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 "" + + code_nodes = question.getElementsByTagName("code") + code = (code_nodes[0].childNodes[0].data).strip() if code_nodes else "" + + expected_ans_node = question.getElementsByTagName("expected_answer")[0] + expected_ans = (expected_ans_node.childNodes[0].data).strip() + + new_question = QuestionBank(quiz_num = quiz_num, + description = description, + time_limit = time_limit, + options = options, + code = code, + expected_ans = expected_ans, + ) + new_question.save() + + + +class Command(NoArgsCommand): + + def handle_noargs(self, **options): + """ Just copied the code from seed_db.py """ + + seed_que() diff -r 6233cf13fc12 -r 456b7b9e3d13 quiz/models.py --- a/quiz/models.py Wed Apr 21 00:51:20 2010 +0530 +++ b/quiz/models.py Wed Apr 21 11:08:44 2010 +0530 @@ -4,6 +4,8 @@ from offline.event.models import Event class Profile(models.Model): + """ A profile for quiz takers. + """ user = models.ForeignKey(User) profession = models.CharField(max_length=20,help_text="(Ex: Faculty, Student etc.)") diff -r 6233cf13fc12 -r 456b7b9e3d13 templates/display_question.html --- a/templates/display_question.html Wed Apr 21 00:51:20 2010 +0530 +++ b/templates/display_question.html Wed Apr 21 11:08:44 2010 +0530 @@ -19,8 +19,13 @@ {% endblock %} {% block content %} +{{question.description}}
+{% if question.code %} +
Code +
{{question.code}}
+{% endif %} +
- {{question.description}}