2
|
1 |
#!/usr/bin/python
|
|
2 |
|
|
3 |
from django.contrib.auth.models import User
|
|
4 |
|
|
5 |
from django.db import IntegrityError
|
|
6 |
|
|
7 |
from workshop.reg.models import Event
|
|
8 |
from workshop.reg.utils import gen_key
|
|
9 |
|
|
10 |
def create_user(email, password, firstname="", lastname=""):
|
|
11 |
""" create a user with random username and set the password.
|
|
12 |
"""
|
|
13 |
|
|
14 |
username = ('%s %s'%(firstname, lastname)).title().strip()
|
|
15 |
new_user = User.objects.create_user(username, email, password)
|
|
16 |
new_user.firstname = firstname
|
|
17 |
new_user.lastname = lastname
|
|
18 |
new_user.is_active = False
|
|
19 |
new_user.save()
|
|
20 |
return new_user
|
|
21 |
|
|
22 |
def create_event(title, desc, start_date, stop_date, created_by=None):
|
|
23 |
""" make an event and save it.
|
|
24 |
"""
|
|
25 |
|
|
26 |
new_event = Event()
|
|
27 |
new_event.title = title
|
|
28 |
new_event.description = desc
|
|
29 |
new_event.start_date = start_date
|
|
30 |
new_event.stop_date = stop_date
|
|
31 |
new_event.save()
|
|
32 |
if created_by:
|
|
33 |
new_event.organizers.add(created_by)
|
|
34 |
|
|
35 |
new_event.key = gen_key()
|
|
36 |
while True:
|
|
37 |
try:
|
|
38 |
new_event.save()
|
|
39 |
return new_event
|
|
40 |
except IntegrityError:
|
|
41 |
new_event.key = gen_key()
|