author | nishanth |
Thu, 25 Feb 2010 18:49:17 +0530 | |
changeset 100 | 2275886511df |
parent 31 | 988d4994578f |
child 107 | 4903b4973fc8 |
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 |
|
31 | 29 |
try: |
30 |
user = User.objects.get(username=username) |
|
31 |
return user |
|
32 |
except: |
|
33 |
user = User(username=username, email=email) |
|
34 |
user.set_password(password) |
|
35 |
user.save() |
|
36 |
properties = {'dob':dob, 'gender':gender} |
|
37 |
user_profile = Profile(user=user) |
|
38 |
updateProfile(user_profile, properties) |
|
39 |
return user |
|
12
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
40 |
|
30
055dc4c1db57
fixed a bug in createSuUser method in events/user.py .
nishanth
parents:
12
diff
changeset
|
41 |
def createSuUser(username,email,password,dob,gender): |
12
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
42 |
""" 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
|
43 |
|
30
055dc4c1db57
fixed a bug in createSuUser method in events/user.py .
nishanth
parents:
12
diff
changeset
|
44 |
su_user = createUser(username,email,password,dob,gender) |
12
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
45 |
su_user.is_staff = True |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
46 |
su_user.is_superuser = True |
a93eebabfeb1
created forms, views, templates, actions for home_page, browse_task.
nishanth
parents:
diff
changeset
|
47 |
su_user.save() |
31 | 48 |
return su_user |