author | nishanth |
Fri, 05 Feb 2010 15:02:55 +0530 | |
changeset 30 | 055dc4c1db57 |
parent 12 | a93eebabfeb1 |
child 31 | 988d4994578f |
permissions | -rw-r--r-- |
12
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
1 |
from django.contrib.auth.models import User |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
2 |
from pytask.taskapp.models import Profile, Task, Comment, Credit |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
3 |
|
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
4 |
""" A collection of helper methods. note that there is no validation done here. |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
5 |
we take care of validation and others checks in methods that invoke these methods. |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
6 |
""" |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
7 |
|
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
8 |
def updateProfile(user_profile, properties): |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
9 |
""" updates the given properties in the profile for a user. |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
10 |
args: |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
11 |
user_profile : a profile object |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
12 |
properties : a dictionary with attributes to set as keys and corresponding values |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
13 |
""" |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
14 |
|
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
15 |
for attr,value in properties.items(): |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
16 |
user_profile.__setattr__(attr,value) |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
17 |
user_profile.save() |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
18 |
|
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
19 |
def createUser(username,email,password,dob,gender): |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
20 |
""" create a user and create a profile and update its properties |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
21 |
args: |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
22 |
username : a username that does not exist |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
23 |
email : a valid email |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
24 |
password : a password |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
25 |
dob : a date object |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
26 |
gender : u'M'/u'F' |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
27 |
""" |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
28 |
|
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
29 |
user = User(username=username, email=email) |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
30 |
user.set_password(password) |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
31 |
user.save() |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
32 |
properties = {'dob':dob, 'gender':gender} |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
33 |
user_profile = Profile(user=user) |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
34 |
updateProfile(user_profile, properties) |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
35 |
return user |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
36 |
|
30
055dc4c1db57
fixed a bug in createSuUser method in events/user.py .
nishanth
parents:
12
diff
changeset
|
37 |
def createSuUser(username,email,password,dob,gender): |
12
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
38 |
""" create user using createUser method and set the is_superuser flag """ |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
39 |
|
30
055dc4c1db57
fixed a bug in createSuUser method in events/user.py .
nishanth
parents:
12
diff
changeset
|
40 |
su_user = createUser(username,email,password,dob,gender) |
12
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
41 |
su_user.is_staff = True |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
42 |
su_user.is_superuser = True |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
43 |
su_user.save() |