added seed_db in utils that seeds database with random users and tasks .
authornishanth
Fri, 05 Feb 2010 15:42:35 +0530
changeset 32 78adf44d895d
parent 31 988d4994578f
child 33 0d0ea7b188d5
added seed_db in utils that seeds database with random users and tasks .
taskapp/utils/__init__.py
taskapp/utils/seed_db.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/taskapp/utils/seed_db.py	Fri Feb 05 15:42:35 2010 +0530
@@ -0,0 +1,33 @@
+from datetime import datetime
+from django.contrib.auth.models import User
+from django.http import HttpResponse
+from pytask.taskapp.events import task as taskEvents
+from pytask.taskapp.events import user as userEvents
+
+def seed_db(request):
+    """ a method to seed the database with random data """
+    
+    defaultMentor = userEvents.createSuUser("admin", "admin@example.com", "123456", datetime.now(), "M")
+    
+    for i in range(1,10):
+        
+        username = 'user'+str(i)
+        email = username+'@example.com'
+        password = '123456'
+        dob = datetime.now()
+        gender = "M"
+        userEvents.createUser(username,email,password,dob,gender)
+
+    for i in range(1,21):
+        
+        title = "Task "+str(i)
+        desc = "I am "+title
+        created_by = defaultMentor
+        credits = 20
+        
+        task = taskEvents.createTask(title,desc,created_by,credits)
+        if task:
+            taskEvents.addMentor(task, defaultMentor)
+            taskEvents.publishTask(task)
+        
+    return HttpResponse("Done")