20 '"Todd Larsen" <tlarsen@google.com>', |
20 '"Todd Larsen" <tlarsen@google.com>', |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
22 '"Pawel Solyga" <pawel.solyga@gmail.com>', |
22 '"Pawel Solyga" <pawel.solyga@gmail.com>', |
23 ] |
23 ] |
24 |
24 |
|
25 |
|
26 import logging |
|
27 |
25 from google.appengine.ext import db |
28 from google.appengine.ext import db |
26 from django.utils.translation import ugettext_lazy |
29 from django.utils.translation import ugettext_lazy |
27 |
30 |
|
31 from soc.models import base |
|
32 from soc.views.helpers import forms_helpers |
28 |
33 |
29 class User(db.Model): |
34 |
|
35 class User(base.ModelWithFieldAttributes): |
30 """A user and associated login credentials, the fundamental identity entity. |
36 """A user and associated login credentials, the fundamental identity entity. |
31 |
37 |
32 User is a separate Model class from Person because the same login |
38 User is a separate Model class from Person because the same login |
33 ID may be used to, for example, serve as Contributor in one Program |
39 ID may be used to, for example, serve as Contributor in one Program |
34 and a Reviewer in another. |
40 and a Reviewer in another. |
61 link_name = db.StringProperty(required=True, |
67 link_name = db.StringProperty(required=True, |
62 verbose_name=ugettext_lazy('Link name')) |
68 verbose_name=ugettext_lazy('Link name')) |
63 link_name.help_text = ugettext_lazy( |
69 link_name.help_text = ugettext_lazy( |
64 'Field used in URLs to identify user. ' |
70 'Field used in URLs to identify user. ' |
65 'Lower ASCII characters only.') |
71 'Lower ASCII characters only.') |
66 |
|
67 @staticmethod |
|
68 def doesUserExist(id=None): |
|
69 """Returns if user already exists in the Datastore. |
|
70 |
|
71 Args: |
|
72 user: a Google Account object, |
|
73 """ |
|
74 #: let's do a gql query and check if user exists in datastore |
|
75 data = self.getUserForId(id) |
|
76 if data: |
|
77 return True |
|
78 else: |
|
79 return False |
|
80 |
|
81 @staticmethod |
|
82 def getUserForId(id=None): |
|
83 """Returns User entity from datastore, or None if not found. |
|
84 |
|
85 Args: |
|
86 user: a Google Account object, |
|
87 """ |
|
88 return User.gql('WHERE id = :1', id).get() |
|
89 |
|
90 @staticmethod |
|
91 def getUserForLinkname(link_name=None): |
|
92 """Returns User entity for linkname or None if not found. |
|
93 |
|
94 Args: |
|
95 link_name: linkname used in URLs to identify user, |
|
96 """ |
|
97 return User.gql('WHERE link_name = :1', link_name).get() |
|
98 |
|