author | nishanth |
Mon, 12 Apr 2010 12:32:46 +0530 | |
changeset 13 | 05248e27104a |
parent 9 | e29ecb7819e7 |
child 17 | 125b6fc8f20b |
permissions | -rw-r--r-- |
2 | 1 |
#!/usr/bin/python |
2 |
||
3 |
from django.contrib.auth.models import User |
|
4 |
||
5 |
from django.db import IntegrityError |
|
6 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
7 |
from workshop.reg.models import Profile, Event |
2 | 8 |
from workshop.reg.utils import gen_key |
9 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
10 |
def create_user(email, password, firstname="", lastname="", gender="M", profession="S", affiliated_to="", interests="" ): |
2 | 11 |
""" create a user with random username and set the password. |
12 |
""" |
|
13 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
14 |
while True: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
15 |
try: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
16 |
username = gen_key(8) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
17 |
user = User.objects.get(username=username) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
18 |
except User.DoesNotExist: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
19 |
break |
2 | 20 |
new_user = User.objects.create_user(username, email, password) |
21 |
new_user.firstname = firstname |
|
22 |
new_user.lastname = lastname |
|
23 |
new_user.is_active = False |
|
24 |
new_user.save() |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
25 |
|
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
26 |
new_profile = Profile(user=new_user) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
27 |
new_profile.gender = gender |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
28 |
new_profile.profession = profession |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
29 |
new_profile.affiliated_to = affiliated_to |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
30 |
new_profile.interests = interests |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
31 |
|
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
32 |
while True: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
33 |
try: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
34 |
new_profile.activation_key = gen_key(30) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
35 |
new_profile.save() |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
36 |
return new_user |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
37 |
except IntegrityError: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
38 |
pass |
2 | 39 |
|
8 | 40 |
def create_event(title, description, start_date, stop_date, created_by=None): |
2 | 41 |
""" make an event and save it. |
42 |
""" |
|
43 |
||
44 |
new_event = Event() |
|
45 |
new_event.title = title |
|
8 | 46 |
new_event.description = description |
2 | 47 |
new_event.start_date = start_date |
48 |
new_event.stop_date = stop_date |
|
49 |
new_event.save() |
|
50 |
if created_by: |
|
51 |
new_event.organizers.add(created_by) |
|
52 |
||
53 |
while True: |
|
54 |
try: |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
55 |
new_event.key = gen_key(10) |
2 | 56 |
new_event.save() |
57 |
return new_event |
|
58 |
except IntegrityError: |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
59 |
pass |
7 | 60 |
|
61 |
def activate_user(user): |
|
62 |
""" mark the is_active flag as true. |
|
63 |
""" |
|
64 |
||
65 |
user.is_active = True |
|
66 |
user.save() |
|
67 |
return user |
|
9 | 68 |
|
69 |
def reset_password(user): |
|
70 |
""" get a key and set it as password. |
|
71 |
for now, print the key. |
|
72 |
later on add the send mail function. |
|
73 |
""" |
|
74 |
||
75 |
new_password = gen_key(10) |
|
76 |
user.set_password(new_password) |
|
77 |
user.save() |
|
78 |
print "The new password is", new_password |
|
79 |
return new_password |
|
80 |
||
81 |
def change_password(user, new_password): |
|
82 |
""" for now just set the password and be done with it. |
|
83 |
later on, if we want to do something else also then we can add them here. |
|
84 |
""" |
|
85 |
||
86 |
user.set_password(new_password) |
|
87 |
user.save() |
|
88 |
||
89 |