Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(43)

Delta Between Two Patch Sets: appengine_django/auth/models.py

Issue 908: [issue6] Google's Users API Integration (Closed) SVN Base: http://google-app-engine-django.googlecode.com/svn/trunk/
Left Patch Set: Revised patch to support Django 0.96 Created 4 months, 4 weeks ago
Right Patch Set: DjangoUserModel, better helpers integration for authentication Created 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and 12 # See the License for the specific language governing permissions and
13 # limitations under the License. 13 # limitations under the License.
14 14
15 """ 15 """
16 DjangoUser model for authentication framework 16 DjangoUser model for authentication framework
17 """ 17 """
18 18
19 from django.contrib.auth.models import SiteProfileNotAvailable 19 from django.contrib.auth.models import SiteProfileNotAvailable
20 from django.core import mail 20 from django.core import mail
21 from django.core.exceptions import ImproperlyConfigured 21 from django.core.exceptions import ImproperlyConfigured
22 from django.db import models 22 from django.db import models
23 23 from django.db.models.manager import EmptyManager
24 try:
25 # Django >= 0.97
26 from django.db.models.manager import EmptyManager
27 except ImportError:
28 # Django = 0.96
29 from django.db.models.manager import Manager
30 class EmptyManager(Manager):
31 def get_query_set(self):
32 return self.get_empty_query_set()
33 24
34 from google.appengine.api import users 25 from google.appengine.api import users
35 from google.appengine.ext import db 26 from google.appengine.ext import db
36 27
37 from appengine_django.models import BaseModel 28 from appengine_django.models import BaseModel
38 29
39 30
40 class DjangoUser(BaseModel): 31 class DjangoUser(BaseModel):
41 """A model the same attributes and method as a Django user model. 32 """A model the same attributes and method as a Django user model.
42 33
(...skipping 18 matching lines...) Show 10 above Show 10 below
61 user_permissions = EmptyManager() 52 user_permissions = EmptyManager()
62 53
63 def __unicode__(self): 54 def __unicode__(self):
64 return self.username 55 return self.username
65 56
66 def __str__(self): 57 def __str__(self):
67 return unicode(self).encode('utf-8') 58 return unicode(self).encode('utf-8')
68 59
69 @classmethod 60 @classmethod
70 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
71 query = cls.all().filter("user =", user) 68 query = cls.all().filter("user =", user)
72 if query.count() == 0: 69 if query.count() == 0:
73 django_user = cls(user=user, email=user.email(), username=user.nickname()) 70 django_user = cls(user=user, email=email, username=nickname)
74 django_user.save() 71 django_user.save()
75 else: 72 else:
76 django_user = query.get() 73 django_user = query.get()
77 return django_user 74 return django_user
78 75
79 def set_password(self, raw_password): 76 def set_password(self, raw_password):
80 raise NotImplementedError 77 raise NotImplementedError
81 78
82 def check_password(self, raw_password): 79 def check_password(self, raw_password):
83 raise NotImplementedError 80 raise NotImplementedError
(...skipping 47 matching lines...) Show 10 above Show 10 below
131 message, 128 message,
132 from_email, 129 from_email,
133 [self.email]) 130 [self.email])
134 131
135 def get_profile(self): 132 def get_profile(self):
136 """ 133 """
137 Returns site-specific profile for this user. Raises 134 Returns site-specific profile for this user. Raises
138 SiteProfileNotAvailable if this site does not allow profiles. 135 SiteProfileNotAvailable if this site does not allow profiles.
139 136
140 When using the App Engine authentication framework, users are created 137 When using the App Engine authentication framework, users are created
141 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.
142 """ 144 """
143 if not hasattr(self, '_profile_cache'): 145 if not hasattr(self, '_profile_cache'):
144 from django.conf import settings 146 from django.conf import settings
145 if not hasattr(settings, "AUTH_PROFILE_MODULE"): 147 if not hasattr(settings, "AUTH_PROFILE_MODULE"):
146 raise SiteProfileNotAvailable 148 raise SiteProfileNotAvailable
147 try: 149 try:
148 app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.') 150 app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.')
149 model = models.get_model(app_label, model_name) 151 model = models.get_model(app_label, model_name)
150 self._profile_cache = model.all().filter("user =", self).get() 152 self._profile_cache = model.all().filter("user =", self).get()
151 if not self._profile_cache: 153 if not self._profile_cache and hasattr(model, "create_profile"):
152 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
153 except (ImportError, ImproperlyConfigured): 155 except (ImportError, ImproperlyConfigured):
154 raise SiteProfileNotAvailable 156 raise SiteProfileNotAvailable
155 return self._profile_cache 157 return self._profile_cache
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r338