taskapp/utils/seed_db.py
author nishanth
Fri, 05 Feb 2010 15:42:35 +0530
changeset 32 78adf44d895d
permissions -rw-r--r--
added seed_db in utils that seeds database with random users and tasks .
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
     1
from datetime import datetime
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
     2
from django.contrib.auth.models import User
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
     3
from django.http import HttpResponse
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
     4
from pytask.taskapp.events import task as taskEvents
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
     5
from pytask.taskapp.events import user as userEvents
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
     6
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
     7
def seed_db(request):
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
     8
    """ a method to seed the database with random data """
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
     9
    
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    10
    defaultMentor = userEvents.createSuUser("admin", "admin@example.com", "123456", datetime.now(), "M")
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    11
    
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    12
    for i in range(1,10):
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    13
        
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    14
        username = 'user'+str(i)
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    15
        email = username+'@example.com'
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    16
        password = '123456'
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    17
        dob = datetime.now()
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    18
        gender = "M"
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    19
        userEvents.createUser(username,email,password,dob,gender)
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    20
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    21
    for i in range(1,21):
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    22
        
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    23
        title = "Task "+str(i)
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    24
        desc = "I am "+title
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    25
        created_by = defaultMentor
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    26
        credits = 20
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    27
        
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    28
        task = taskEvents.createTask(title,desc,created_by,credits)
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    29
        if task:
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    30
            taskEvents.addMentor(task, defaultMentor)
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    31
            taskEvents.publishTask(task)
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    32
        
78adf44d895d added seed_db in utils that seeds database with random users and tasks .
nishanth
parents:
diff changeset
    33
    return HttpResponse("Done")