| LEFT | RIGHT |
|---|---|
| 1 # Copyright 2008 Google Inc. | 1 # Copyright 2008 Google Inc. |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 41 matching lines...) Show 10 above Show 10 below | |
| 52 user_permissions = EmptyManager() | 52 user_permissions = EmptyManager() |
| 53 | 53 |
| 54 def __unicode__(self): | 54 def __unicode__(self): |
| 55 return self.username | 55 return self.username |
| 56 | 56 |
| 57 def __str__(self): | 57 def __str__(self): |
| 58 return unicode(self).encode('utf-8') | 58 return unicode(self).encode('utf-8') |
| 59 | 59 |
| 60 @classmethod | 60 @classmethod |
| 61 def get_djangouser_for_user(cls, user): | 61 def get_djangouser_for_user(cls, user): |
| 62 email = user.email() | |
| 63 assert email | |
| 64 nickname = user.nickname() | |
| 65 if '@' in nickname: | |
| 66 nickname = nickname.split('@', 1)[0] | |
| 67 assert nickname | |
|
mattbrown.nz
2008/05/18 11:23:43
These statements are only used to create a user, s
aalbrecht
2008/05/18 19:17:47
On 2008/05/18 11:23:43, mattbrown.nz wrote:
> Thes
| |
| 62 query = cls.all().filter("user =", user) | 68 query = cls.all().filter("user =", user) |
| 63 if query.count() == 0: | 69 if query.count() == 0: |
| 64 django_user = cls(user=user, email=user.email(), username=user.nickname()) | 70 django_user = cls(user=user, email=email, username=nickname) |
| 65 django_user.save() | 71 django_user.save() |
| 66 else: | 72 else: |
| 67 django_user = query.get() | 73 django_user = query.get() |
| 68 return django_user | 74 return django_user |
| 69 | 75 |
| 70 def set_password(self, raw_password): | 76 def set_password(self, raw_password): |
| 71 raise NotImplementedError | 77 raise NotImplementedError |
| 72 | 78 |
| 73 def check_password(self, raw_password): | 79 def check_password(self, raw_password): |
| 74 raise NotImplementedError | 80 raise NotImplementedError |
| (...skipping 47 matching lines...) Show 10 above Show 10 below | |
| 122 message, | 128 message, |
| 123 from_email, | 129 from_email, |
| 124 [self.email]) | 130 [self.email]) |
| 125 | 131 |
| 126 def get_profile(self): | 132 def get_profile(self): |
| 127 """ | 133 """ |
| 128 Returns site-specific profile for this user. Raises | 134 Returns site-specific profile for this user. Raises |
| 129 SiteProfileNotAvailable if this site does not allow profiles. | 135 SiteProfileNotAvailable if this site does not allow profiles. |
| 130 | 136 |
| 131 When using the App Engine authentication framework, users are created | 137 When using the App Engine authentication framework, users are created |
| 132 automatically. | 138 automatically. To give projects the chance to create profiles for |
| 139 new users, this method checks for the presence of a classmethod in the | |
| 140 profile model called 'create_profile' if no profile for a user can be found. | |
| 141 If such a method exists, it is called with a DjangoUser as it's only | |
| 142 argument to intially create a profile for this user. The method must return | |
| 143 the created profile. | |
| 133 """ | 144 """ |
| 134 if not hasattr(self, '_profile_cache'): | 145 if not hasattr(self, '_profile_cache'): |
| 135 from django.conf import settings | 146 from django.conf import settings |
| 136 if not hasattr(settings, "AUTH_PROFILE_MODULE"): | 147 if not hasattr(settings, "AUTH_PROFILE_MODULE"): |
| 137 raise SiteProfileNotAvailable | 148 raise SiteProfileNotAvailable |
| 138 try: | 149 try: |
| 139 app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.') | 150 app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.') |
| 140 model = models.get_model(app_label, model_name) | 151 model = models.get_model(app_label, model_name) |
| 141 self._profile_cache = model.all().filter("user =", self).get() | 152 self._profile_cache = model.all().filter("user =", self).get() |
| 142 if not self._profile_cache: | 153 if not self._profile_cache and hasattr(model, "create_profile"): |
| 143 raise model.DoesNotExist | 154 self._profile_cache = model.create_profile(self) |
|
mattbrown.nz
2008/05/18 11:23:43
else:
raise DoesNotExist
To stay consistent with
aalbrecht
2008/05/18 19:17:47
On 2008/05/18 11:23:43, mattbrown.nz wrote:
> else
| |
| 144 except (ImportError, ImproperlyConfigured): | 155 except (ImportError, ImproperlyConfigured): |
| 145 raise SiteProfileNotAvailable | 156 raise SiteProfileNotAvailable |
| 146 return self._profile_cache | 157 return self._profile_cache |
| LEFT | RIGHT |