modified createUser method in events/user.py .
authornishanth
Fri, 05 Feb 2010 15:40:47 +0530
changeset 31 988d4994578f
parent 30 055dc4c1db57
child 32 78adf44d895d
modified createUser method in events/user.py .
taskapp/events/user.py
urls.py
--- a/taskapp/events/user.py	Fri Feb 05 15:02:55 2010 +0530
+++ b/taskapp/events/user.py	Fri Feb 05 15:40:47 2010 +0530
@@ -26,13 +26,17 @@
         gender : u'M'/u'F' 
     """
 
-    user = User(username=username, email=email)
-    user.set_password(password)
-    user.save()
-    properties = {'dob':dob, 'gender':gender}
-    user_profile = Profile(user=user)
-    updateProfile(user_profile, properties)
-    return user
+    try:
+        user = User.objects.get(username=username)
+        return user
+    except:        
+        user = User(username=username, email=email)
+        user.set_password(password)
+        user.save()
+        properties = {'dob':dob, 'gender':gender}
+        user_profile = Profile(user=user)
+        updateProfile(user_profile, properties)
+        return user
     
 def createSuUser(username,email,password,dob,gender):
     """ create user using createUser method and set the is_superuser flag """
@@ -41,3 +45,4 @@
     su_user.is_staff = True
     su_user.is_superuser = True
     su_user.save()
+    return su_user
--- a/urls.py	Fri Feb 05 15:02:55 2010 +0530
+++ b/urls.py	Fri Feb 05 15:40:47 2010 +0530
@@ -7,6 +7,8 @@
 from pytask.taskapp.views.user import homepage, register, user_login, user_logout, view_my_profile, edit_my_profile, browse_users
 from pytask.taskapp.views.task import browse_tasks, view_task, create_task, add_mentor, add_tasks, claim_task, assign_task
 
+from pytask.taskapp.utils.seed_db import seed_db
+
 urlpatterns = patterns('',
     # Example:
     # (r'^pytask/', include('pytask.foo.urls')),
@@ -34,4 +36,6 @@
     (r'^user/view/uid=(\d+)$', view_my_profile),
     (r'^user/edit/?$', edit_my_profile),
     (r'^user/browse/?$',browse_users),
+    
+    (r'^seed_db/$', seed_db),
 )