reg/events.py
changeset 6 057498d12450
parent 2 c11afa8623f7
child 7 af9ab5ad2786
equal deleted inserted replaced
5:37e4027fba48 6:057498d12450
     2 
     2 
     3 from django.contrib.auth.models import User
     3 from django.contrib.auth.models import User
     4 
     4 
     5 from django.db import IntegrityError
     5 from django.db import IntegrityError
     6 
     6 
     7 from workshop.reg.models import Event
     7 from workshop.reg.models import Profile, Event
     8 from workshop.reg.utils import gen_key
     8 from workshop.reg.utils import gen_key
     9 
     9 
    10 def create_user(email, password, firstname="", lastname=""):
    10 def create_user(email, password, firstname="", lastname="", gender="M", profession="S", affiliated_to="", interests="" ):
    11     """ create a user with random username and set the password.
    11     """ create a user with random username and set the password.
    12     """
    12     """
    13 
    13 
    14     username = ('%s %s'%(firstname, lastname)).title().strip()
    14     while True:
       
    15         try:
       
    16             username = gen_key(8)
       
    17             user = User.objects.get(username=username)
       
    18         except User.DoesNotExist:
       
    19             break
    15     new_user = User.objects.create_user(username, email, password)
    20     new_user = User.objects.create_user(username, email, password)
    16     new_user.firstname = firstname
    21     new_user.firstname = firstname
    17     new_user.lastname = lastname
    22     new_user.lastname = lastname
    18     new_user.is_active = False
    23     new_user.is_active = False
    19     new_user.save()
    24     new_user.save()
    20     return new_user
    25 
       
    26     new_profile = Profile(user=new_user)
       
    27     new_profile.gender = gender
       
    28     new_profile.profession = profession
       
    29     new_profile.affiliated_to = affiliated_to
       
    30     new_profile.interests = interests
       
    31 
       
    32     while True:
       
    33         try:
       
    34             new_profile.activation_key = gen_key(30)
       
    35             new_profile.save()
       
    36             return new_user
       
    37         except IntegrityError:
       
    38             pass
    21 
    39 
    22 def create_event(title, desc, start_date, stop_date, created_by=None):
    40 def create_event(title, desc, start_date, stop_date, created_by=None):
    23     """ make an event and save it.
    41     """ make an event and save it.
    24     """
    42     """
    25 
    43 
    30     new_event.stop_date = stop_date
    48     new_event.stop_date = stop_date
    31     new_event.save()
    49     new_event.save()
    32     if created_by:
    50     if created_by:
    33         new_event.organizers.add(created_by)
    51         new_event.organizers.add(created_by)
    34 
    52 
    35     new_event.key = gen_key()
       
    36     while True:
    53     while True:
    37         try:
    54         try:
       
    55             new_event.key = gen_key(10)
    38             new_event.save()
    56             new_event.save()
    39             return new_event
    57             return new_event
    40         except IntegrityError:
    58         except IntegrityError:
    41             new_event.key = gen_key()
    59             pass
       
    60 '''
       
    61 def mail_user(email):
       
    62     """ get the user 
       
    63 '''