author | Lennard de Rijk <ljvderijk@gmail.com> |
Sat, 28 Feb 2009 13:06:04 +0000 | |
changeset 1559 | 283046e54c01 |
parent 1308 | 35b75ffcbb37 |
child 1650 | 51b5bc38522c |
permissions | -rw-r--r-- |
7
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
2 |
# |
1308
35b75ffcbb37
Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1307
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
7
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
4 |
# |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
8 |
# |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
10 |
# |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
16 |
|
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
17 |
"""This module contains the User Model.""" |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
18 |
|
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
19 |
__authors__ = [ |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
20 |
'"Todd Larsen" <tlarsen@google.com>', |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
78
206e6eeed6c4
Updated User and Person models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
22 |
'"Pawel Solyga" <pawel.solyga@gmail.com>', |
7
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
23 |
] |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
|
118
d2e61a490969
Clean up User Model and User profile edit view now that soc.logic.site.id_user
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
25 |
|
131 | 26 |
from google.appengine.api import users |
7
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
27 |
from google.appengine.ext import db |
131 | 28 |
|
970
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
936
diff
changeset
|
29 |
from django.utils.translation import ugettext |
7
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
30 |
|
533
ba3309b2fd30
Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents:
529
diff
changeset
|
31 |
import soc.models.linkable |
7
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
32 |
|
118
d2e61a490969
Clean up User Model and User profile edit view now that soc.logic.site.id_user
Todd Larsen <tlarsen@google.com>
parents:
99
diff
changeset
|
33 |
|
533
ba3309b2fd30
Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents:
529
diff
changeset
|
34 |
class User(soc.models.linkable.Linkable): |
7
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
35 |
"""A user and associated login credentials, the fundamental identity entity. |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
36 |
|
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
37 |
User is a separate Model class from Person because the same login |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
38 |
ID may be used to, for example, serve as Contributor in one Program |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
39 |
and a Reviewer in another. |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
40 |
|
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
41 |
Also, this allows a Person to, in the future, re-associate that |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
42 |
Person entity with a different Google Account if necessary. |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
43 |
|
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
44 |
A User entity participates in the following relationships implemented |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
45 |
as a db.ReferenceProperty elsewhere in another db.Model: |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
46 |
|
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
47 |
persons) a 1:many relationship of Person entities identified by the |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
48 |
User. This relation is implemented as the 'persons' back-reference |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
49 |
Query of the Person model 'user' reference. |
181
fdd29818a954
Remove Author model (use Person instead). Update models after removing Author. Add new Sponsor, Organization models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
161
diff
changeset
|
50 |
|
fdd29818a954
Remove Author model (use Person instead). Update models after removing Author. Add new Sponsor, Organization models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
161
diff
changeset
|
51 |
documents) a 1:many relationship of Document entities identified by the |
fdd29818a954
Remove Author model (use Person instead). Update models after removing Author. Add new Sponsor, Organization models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
161
diff
changeset
|
52 |
User. This relation is implemented as the 'user' back-reference |
fdd29818a954
Remove Author model (use Person instead). Update models after removing Author. Add new Sponsor, Organization models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
161
diff
changeset
|
53 |
Query of the Document model 'user' reference. |
7
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
54 |
|
193
3d30a7a96ce7
Note 'groups' back-reference from 'founder' property in soc.models.group.Group.
Todd Larsen <tlarsen@google.com>
parents:
181
diff
changeset
|
55 |
groups) a 1:many relationship of Group entities "founded" by the User. |
3d30a7a96ce7
Note 'groups' back-reference from 'founder' property in soc.models.group.Group.
Todd Larsen <tlarsen@google.com>
parents:
181
diff
changeset
|
56 |
This relation is implemented as the 'groups' back-reference Query of |
3d30a7a96ce7
Note 'groups' back-reference from 'founder' property in soc.models.group.Group.
Todd Larsen <tlarsen@google.com>
parents:
181
diff
changeset
|
57 |
the Group model 'founder' reference. |
339
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
298
diff
changeset
|
58 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
298
diff
changeset
|
59 |
responses) a 1:many relationship of Reponse entities submitted by the |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
298
diff
changeset
|
60 |
User. This relation is implemented as the 'responses' back-reference |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
298
diff
changeset
|
61 |
Query of the Response model 'respondent' reference. |
7
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
""" |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
63 |
|
936
b3e1e0c9649c
Enable pick links for all the references we have
Sverre Rabbelier <srabbelier@gmail.com>
parents:
811
diff
changeset
|
64 |
URL_NAME = 'user' |
b3e1e0c9649c
Enable pick links for all the references we have
Sverre Rabbelier <srabbelier@gmail.com>
parents:
811
diff
changeset
|
65 |
|
7
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
#: A Google Account, which also provides a "private" email address. |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
#: This email address is only used in an automated fashion by |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
68 |
#: Melange web applications and is not made visible to other users |
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
#: of any Melange application. |
481
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
339
diff
changeset
|
70 |
account = db.UserProperty(required=True, |
970
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
936
diff
changeset
|
71 |
verbose_name=ugettext('User account')) |
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
936
diff
changeset
|
72 |
account.help_text = ugettext( |
481
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
339
diff
changeset
|
73 |
'A valid Google Account.') |
7
5c72db822ebb
Initial revision of the user.py module, containing the User Model, from the
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
74 |
|
131 | 75 |
#: A list (possibly empty) of former Google Accounts associated with |
76 |
#: this User. |
|
481
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
339
diff
changeset
|
77 |
former_accounts = db.ListProperty(users.User) |
131 | 78 |
|
529
7c5ec72cdcf1
Replace nick_name and its variants with public_name. Remove the
Todd Larsen <tlarsen@google.com>
parents:
512
diff
changeset
|
79 |
#: Required field storing publicly-displayed name. Can be a real name |
7c5ec72cdcf1
Replace nick_name and its variants with public_name. Remove the
Todd Larsen <tlarsen@google.com>
parents:
512
diff
changeset
|
80 |
#: (though this is not recommended), or a nick name or some other public |
7c5ec72cdcf1
Replace nick_name and its variants with public_name. Remove the
Todd Larsen <tlarsen@google.com>
parents:
512
diff
changeset
|
81 |
#: alias. Public names can be any valid UTF-8 text. |
546
850d9a5ad894
Rename the User.public_name Property to simply 'name' (but leave the verbose
Todd Larsen <tlarsen@google.com>
parents:
540
diff
changeset
|
82 |
name = db.StringProperty(required=True, |
970
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
936
diff
changeset
|
83 |
verbose_name=ugettext('Public name')) |
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
936
diff
changeset
|
84 |
name.help_text = ugettext( |
540
e14e9cf23097
Add User.public_name help text, per discussions on melange-soc-dev.
Todd Larsen <tlarsen@google.com>
parents:
533
diff
changeset
|
85 |
'Human-readable name (UTF-8) that will be displayed publicly on the' |
549
00a9ce3dc082
Fix some broken help_text bubbles (they are truncated or not displayed if they
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
86 |
' site.') |
78
206e6eeed6c4
Updated User and Person models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
54
diff
changeset
|
87 |
|
137
0f572149449d
Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents:
131
diff
changeset
|
88 |
#: field storing whether User is a Developer with site-wide access. |
1041
dfe21b16c86c
Added default values to the User model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
970
diff
changeset
|
89 |
is_developer = db.BooleanProperty(default=False, |
970
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
936
diff
changeset
|
90 |
verbose_name=ugettext('Is Developer')) |
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
936
diff
changeset
|
91 |
is_developer.help_text = ugettext( |
549
00a9ce3dc082
Fix some broken help_text bubbles (they are truncated or not displayed if they
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
92 |
'Field used to indicate user with site-wide Developer access.') |
540
e14e9cf23097
Add User.public_name help text, per discussions on melange-soc-dev.
Todd Larsen <tlarsen@google.com>
parents:
533
diff
changeset
|
93 |
|
1076
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
94 |
#: field storing wheter the User has agreed to the site-wide Terms of Service. |
811
9e56019eb218
Add "agrees to site-wide Terms of Service" boolean property for all Users.
Todd Larsen <tlarsen@google.com>
parents:
549
diff
changeset
|
95 |
#: (Not a required field because the Terms of Service might not be present |
9e56019eb218
Add "agrees to site-wide Terms of Service" boolean property for all Users.
Todd Larsen <tlarsen@google.com>
parents:
549
diff
changeset
|
96 |
#: when the first User profile is created when bootstrapping the site.) |
1076
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
97 |
agreed_to_tos = db.BooleanProperty(required=False, default=False, |
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
98 |
verbose_name=ugettext('I Agree to the Terms of Service')) |
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
99 |
agreed_to_tos.help_text = ugettext( |
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
100 |
'Indicates whether the user agreed to the site-wide Terms of Service.') |
811
9e56019eb218
Add "agrees to site-wide Terms of Service" boolean property for all Users.
Todd Larsen <tlarsen@google.com>
parents:
549
diff
changeset
|
101 |
|
1076
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
102 |
#: field storing when the User has agreed to the site-wide Terms of Service. |
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
103 |
#: (Not a required field because the Terms of Service might not be present |
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
104 |
#: when the first User profile is created when bootstrapping the site.) |
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
105 |
agreed_to_tos_on = db.DateTimeProperty(required=False, default=None, |
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
106 |
verbose_name=ugettext('Has agreed to the Terms of Service on')) |
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
107 |
agreed_to_tos_on.help_text = ugettext( |
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
108 |
'Indicates when the user agreed to the site-wide Terms of Service.') |
063194eaf87b
Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1046
diff
changeset
|
109 |
|
1157
76e2ed09661c
Added status property to the user model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1076
diff
changeset
|
110 |
#: field storing the status of this User. |
76e2ed09661c
Added status property to the user model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1076
diff
changeset
|
111 |
#: valid: Is just that, it's a valid User. |
76e2ed09661c
Added status property to the user model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1076
diff
changeset
|
112 |
#: invalid: This means that this User has been excluded from using the website. |
76e2ed09661c
Added status property to the user model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1076
diff
changeset
|
113 |
status = db.StringProperty(required=True, default='valid', |
76e2ed09661c
Added status property to the user model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1076
diff
changeset
|
114 |
choices=['valid', 'invalid'],) |
76e2ed09661c
Added status property to the user model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1076
diff
changeset
|
115 |
status.help_text = ugettext( |
76e2ed09661c
Added status property to the user model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1076
diff
changeset
|
116 |
'Indicates the status of the User. Invalid means that this account ' |
76e2ed09661c
Added status property to the user model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1076
diff
changeset
|
117 |
'has been excluded from using the website.') |