profile/management/commands/seed_db.py
author Nishanth Amuluru <nishanth@fossee.in>
Fri, 07 Jan 2011 11:42:34 +0530
changeset 269 dde894b36370
parent 263 48d68e75e9cc
child 279 d84a3781b979
permissions -rw-r--r--
created view for editing profile and created corresponding template
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
263
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     1
import sys
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     2
from datetime import datetime
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     3
from django.core.management.base import NoArgsCommand
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     4
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     5
from django.contrib.auth.models import User
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     6
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     7
from pytask.profile.models import Profile
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     8
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     9
def seed_db():
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    10
    """ a method to seed the database with random data """
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    11
    
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    12
    
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    13
    for i in range(1,21):
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    14
        
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    15
        username = 'user'+str(i)
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    16
        email = username+'@example.com'
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    17
        password = '123456'
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    18
        dob = datetime.now()
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    19
        gender = "M"
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    20
        aboutme = "I am User"+str(i)
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    21
        address = "I live in street"+str(i)
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    22
        phonenum = "1234567890"
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    23
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    24
        new_user = User.objects.create_user(username=username,
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    25
                                            email=email,
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    26
                                            password=password)
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    27
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    28
        new_profile = Profile()
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    29
        new_profile.user = new_user
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    30
        new_profile.dob = dob
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    31
        new_profile.aboutme = aboutme
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    32
        new_profile.gender = gender
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    33
        new_profile.address = address
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    34
        new_profile.phonenum = phonenum
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    35
        if i%2 == 0:
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    36
            new_profile.rights = "CT"
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    37
        elif i%3 == 0:
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    38
            new_profile.rights = "CR"
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    39
        new_profile.save()
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    40
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    41
class Command(NoArgsCommand):
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    42
    
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    43
    def handle_noargs(self, **options):
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    44
        """ Just copied the code from seed_db.py """
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    45
        
48d68e75e9cc Added seed_db
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    46
        seed_db()