fixed the display of question
authornishanth
Wed, 21 Apr 2010 12:11:19 +0530
changeset 29 ea1c0110e989
parent 28 456b7b9e3d13
child 30 a07d375efcc9
fixed the display of question
question_bank.xml
quiz/management/commands/seed_db.py
quiz/views.py
templates/display_question.html
--- a/question_bank.xml	Wed Apr 21 11:08:44 2010 +0530
+++ b/question_bank.xml	Wed Apr 21 12:11:19 2010 +0530
@@ -50,25 +50,42 @@
 				len\( a \) 
 			</expected_answer>
 		</question>
-
-	</day1quiz1>
-
-	<day1quiz2>
 		<question>
 			<description>
 				What is the maximum number that can be represented natively in Python.
 			</description>
 			<time_limit>
-				30
+				15
 			</time_limit>
 			<options>
 				Infinite
 				2**32
 			</options>
 			<expected_answer>
-				1
+				Infinite
 			</expected_answer>
 		</question>
-	</day1quiz2>
+
+		<question>
+			<description>
+				There is a bug in this code. What is the bug.
+			</description>
+			<time_limit>
+				30
+			</time_limit>
+			<code>
+for i in range(5):
+    plot(i,sin(i))
+
+			</code>
+			<expected_answer>
+				plot(i,sin(i))
+			</expected_answer>
+		</question>
+	
+	</day1quiz1>
+
+	<day1quiz2>
+</day1quiz2>
 
 </questionbank>
--- a/quiz/management/commands/seed_db.py	Wed Apr 21 11:08:44 2010 +0530
+++ b/quiz/management/commands/seed_db.py	Wed Apr 21 12:11:19 2010 +0530
@@ -13,28 +13,6 @@
     ev.stop_date = datetime.now()
     ev.quiz_status = '11'
     ev.save()
-
-    q1 = QuestionBank()
-    q1.quiz_num = "11"
-    q1.description = "How do you combine two lists a and b"
-    q1.time_limit = 15
-    q1.expected_ans = r"a + b"
-    q1.save()
-
-    q2 = QuestionBank()
-    q2.quiz_num = '11'
-    q2.description = "What IPython magic command would you use to obtain the code that you have already typed."
-    q2.time_limit = 15
-    q2.expected_ans = r"%hist"
-    q2.save()
-
-    q3 = QuestionBank()
-    q3.quiz_num = "11"
-    q3.description = "a = [1, 2, 5, 9]. How do you add 10 to end of this list."
-    q3.time_limit = 30
-    q3.expected_ans = r"a.append(10)"
-    q3.save()
-
     
 class Command(NoArgsCommand):
     
--- a/quiz/views.py	Wed Apr 21 11:08:44 2010 +0530
+++ b/quiz/views.py	Wed Apr 21 12:11:19 2010 +0530
@@ -153,7 +153,8 @@
         else:
             return redirect('/quiz/answer/%s'%quiz.key)
     else:
-        return render_to_response('display_question.html', {'question':question})
+        options = [ _.strip() for _ in question.options.split('\n') ] if question.options else []
+        return render_to_response('display_question.html', {'question':question, 'options':options})
 
 def quiz_complete(request):
     """ display thanq and log the user out.
--- a/templates/display_question.html	Wed Apr 21 11:08:44 2010 +0530
+++ b/templates/display_question.html	Wed Apr 21 12:11:19 2010 +0530
@@ -19,14 +19,23 @@
     </script>
 {% endblock %}
 {% block content %}
-{{question.description}}	<br />
+{{question.description|linebreaksbr}}	<br />
 {% if question.code %}
-<fieldset><legend>Code</legend>
-<pre>{{question.code}}</pre></fieldset>
+<br />
+<fieldset><pre>{{question.code}}</pre></fieldset>
 {% endif %}
-
+<br />
+Answer:<br />
 <form action="" method="post" id="queform">
-		<textarea name="answer"></textarea><br />
+		{% if options %}
+		{% for option in options %}	
+		<input name="answer" type="radio" value="{{option}}" > {{option}} <br />
+		{% endfor %}
+		<br />
+</select>
+{% else %}
+<textarea name="answer" rows="10" cols="40"></textarea><br />
+{% endif %}
 		<input type="button" value="Time left: {{question.time_limit}} secs" id="time_left">
 </form>
 {% endblock %}