quiz/management/commands/seed_db.py
author nishanth
Tue, 20 Apr 2010 19:20:15 +0530
changeset 15 99af908a4174
child 22 fe197c0c9903
permissions -rw-r--r--
added questions thro seed_db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
     1
import sys
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
     2
from datetime import datetime
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
     3
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
     4
from django.core.management.base import NoArgsCommand
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
     5
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
     6
from offline.event.models import Event
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
     7
from offline.quiz.models import QuestionBank
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
     8
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
     9
def seed_db():
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    10
    ev = Event()
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    11
    ev.title = "Some Workshop"
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    12
    ev.start_date = datetime.now()
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    13
    ev.stop_date = datetime.now()
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    14
    ev.quiz_status = '11'
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    15
    ev.save()
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    16
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    17
    q1 = QuestionBank()
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    18
    q1.quiz_num = "11"
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    19
    q1.description = "How do you combine two lists a and b"
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    20
    q1.type = 'S'
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    21
    q1.time_limit = 15
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    22
    q1.expected_ans = r"a + b"
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    23
    q1.save()
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    24
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    25
    q2 = QuestionBank()
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    26
    q2.quiz_num = '11'
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    27
    q2.description = "What IPython magic command would you use to obtain the code that you have already typed."
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    28
    q2.type = "S"
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    29
    q2.time_limit = 15
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    30
    q2.expected_ans = r"%hist"
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    31
    q2.save()
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    32
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    33
    q3 = QuestionBank()
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    34
    q3.quiz_num = "11"
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    35
    q3.description = "a = [1, 2, 5, 9]. How do you add 10 to end of this list."
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    36
    q3.type = "S"
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    37
    q3.time_limit = 30
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    38
    q3.expected_ans = r"a.append(10)"
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    39
    q3.save()
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    40
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    41
    
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    42
class Command(NoArgsCommand):
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    43
    
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    44
    def handle_noargs(self, **options):
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    45
        """ Just copied the code from seed_db.py """
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    46
        
99af908a4174 added questions thro seed_db
nishanth
parents:
diff changeset
    47
        seed_db()