[Python-checkins] r85162 - in tracker/instances/python-dev/rietveld: Makefile codereview.diff roundup_helper/middleware.py
martin.v.loewis
python-checkins at python.org
Sat Oct 2 08:56:58 CEST 2010
Author: martin.v.loewis
Date: Sat Oct 2 08:56:58 2010
New Revision: 85162
Log:
Make roundup users, django users and codereview accounts
all have the same IDs.
Added:
tracker/instances/python-dev/rietveld/codereview.diff (contents, props changed)
Modified:
tracker/instances/python-dev/rietveld/Makefile
tracker/instances/python-dev/rietveld/roundup_helper/middleware.py
Modified: tracker/instances/python-dev/rietveld/Makefile
==============================================================================
--- tracker/instances/python-dev/rietveld/Makefile (original)
+++ tracker/instances/python-dev/rietveld/Makefile Sat Oct 2 08:56:58 2010
@@ -3,7 +3,7 @@
default:
@echo "Run 'make all' to fetch required sources to run this example."
-all: static templates codereview django gae2django syncdb
+all: static templates_svn codereview django gae2django syncdb
@echo "Run './manage.py runserver 127.0.0.1:8000' to run Rietveld."
clean: clean_local clean_external
@@ -27,6 +27,7 @@
codereview:
svn co http://rietveld.googlecode.com/svn/trunk/codereview@$(RIETVELDREV)
+ patch -p0 < codereview.diff
static:
svn co http://rietveld.googlecode.com/svn/trunk/static@$(RIETVELDREV)
Added: tracker/instances/python-dev/rietveld/codereview.diff
==============================================================================
--- (empty file)
+++ tracker/instances/python-dev/rietveld/codereview.diff Sat Oct 2 08:56:58 2010
@@ -0,0 +1,23 @@
+Index: codereview/models.py
+===================================================================
+--- codereview/models.py (Revision 510)
++++ codereview/models.py (Arbeitskopie)
+@@ -520,14 +520,14 @@
+ @classmethod
+ def get_account_for_user(cls, user):
+ """Get the Account for a user, creating a default one if needed."""
+- email = user.email()
+- assert email
+- key = '<%s>' % email
+ # Since usually the account already exists, first try getting it
+ # without the transaction implied by get_or_insert().
+- account = cls.get_by_key_name(key)
++ # Roundup adjustment: accounts will have the same IDs as users
++ account = cls.get_by_id(user.id)
+ if account is not None:
+ return account
++ # Not found, don't auto-create in any case
++ raise engine.FetchError('account not found')
+ nickname = cls.create_nickname_for_user(user)
+ return cls.get_or_insert(key, user=user, email=email, nickname=nickname,
+ fresh=True)
Modified: tracker/instances/python-dev/rietveld/roundup_helper/middleware.py
==============================================================================
--- tracker/instances/python-dev/rietveld/roundup_helper/middleware.py (original)
+++ tracker/instances/python-dev/rietveld/roundup_helper/middleware.py Sat Oct 2 08:56:58 2010
@@ -1,17 +1,12 @@
from models import Session, User
+from codereview.models import Account
from django.contrib import auth
from django.contrib.auth.backends import RemoteUserBackend
class UserBackend(RemoteUserBackend):
- def configure_user(self, user):
- roundup_user = User.objects.filter(_username=user.username)[0]
- user.email = roundup_user._address
- user.save()
- from codereview import models
- account = models.Account.get_account_for_user(user)
- account.nickname = user.username
- account.save()
- return user
+ # auto-creation of django users should not be necessary,
+ # as they should have been created before, so suppress it here.
+ create_unknown_user = False
class LookupRoundupUser(object):
@@ -27,21 +22,24 @@
username = eval(session[0].session_value)['user']
# the username comes from the cookie, so it really ought to exist
roundup_user = User.objects.filter(_username=username)[0]
- if not roundup_user._address:
- # Rietveld insists that user objects must have email addresses
- return
- # Taken from RemoteUserMiddleware: auto-create the user if it's new
+ # if we already have a user from the session, we are done.
if request.user.is_authenticated():
if request.user.username == username:
return
- # We are seeing this user for the first time in this session, attempt
- # to authenticate the user.
+ # We see the user for the first time. Authenticate it, and create
+ # codereview account if none exists.
user = auth.authenticate(remote_user=username)
- if user:
- # User is valid. Set request.user and persist user in the session
- # by logging the user in.
- request.user = user
- auth.login(request, user)
+ if not user:
+ return
+ # User is valid. Set request.user and persist user in the session
+ # by logging the user in.
+ request.user = user
+ account = Account.get_by_id(user.id)
+ if not account:
+ account = Account(id=user.id, user=user, email=user.email,
+ nickname=username, fresh=True)
+ account.put()
+ auth.login(request, user)
def logout(self, request):
# Clear django session if roundup session is gone.
More information about the Python-checkins
mailing list