reg/management/commands/seed_db.py
author nishanth
Thu, 15 Apr 2010 14:50:47 +0530
changeset 44 7d748db0c7c3
parent 23 42e2a810e1c8
child 66 244da980983b
permissions -rw-r--r--
now show report page does not show report if there are no feedbacks .
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
     1
import sys
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
     2
from datetime import datetime
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
     3
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
     4
from django.core.management.base import NoArgsCommand
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
     5
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
     6
from django.contrib.auth.models import User
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
     7
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
     8
from workshop.reg.events import create_user, create_event
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
     9
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    10
def seed_db():
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    11
    """ a method to seed the database with random data """
23
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 2
diff changeset
    12
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 2
diff changeset
    13
    user = create_user('admin@example.com', '12345678', 'Admin', 'Fossee')
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 2
diff changeset
    14
    user.is_active = True
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 2
diff changeset
    15
    user.is_staff = True
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 2
diff changeset
    16
    user.is_superuser = True
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 2
diff changeset
    17
    user.save()
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 2
diff changeset
    18
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 2
diff changeset
    19
"""    
2
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    20
    for i in range(20):
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    21
        user = create_user('user'+str(i)+'@example.com','123456', 'User', str(i))
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    22
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    23
    for i in range(5):
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    24
        create_event("workshop"+str(i), "This is workshop"+str(i), datetime(2010, 4, i+4), datetime(2010, 4, i+6), user)
23
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 2
diff changeset
    25
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 2
diff changeset
    26
"""
2
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    27
    
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    28
class Command(NoArgsCommand):
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    29
    
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    30
    def handle_noargs(self, **options):
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    31
        """ Just copied the code from seed_db.py """
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    32
        
c11afa8623f7 incorporated gen_key .
nishanth
parents:
diff changeset
    33
        seed_db()