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