Move DBModel._id -> DBModel.id

We were refering to model._id in most of the code base as this is
what Mongo uses. However, each use of _id required a) fixup of queries:
e.g. what we did in our find() and find_one() functions moving all
'_id' to 'id'. It also required using AliasFields to make the ._id
attribute available. This all means lots of superfluous fixing and
transitioning in a SQL world.

It will also not work in the long run. Much newer code already refers
to the objects by model.id (e.g. in the oauth plugin), which will break
with Mongo. So let's be honest, rip out the _id mongoism and live with
.id as the one canonical way to address objects.

This commit modifies all users and providers of model._id to use
model.id instead. This patch works with or without Mongo removed first,
but will break Mongo usage (even more than before)

I have not bothered to fixup db.mongo.* and db.sql.convert
(which converts from Mongo to SQL)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth
2012-11-30 10:49:06 +01:00
parent 7e55bcb898
commit 5c2b84869f
30 changed files with 96 additions and 119 deletions

View File

@@ -109,7 +109,7 @@ def send_verification_email(user, request):
'verification_url': EMAIL_VERIFICATION_TEMPLATE.format(
host=request.host,
uri=request.urlgen('mediagoblin.auth.verify_email'),
userid=unicode(user._id),
userid=unicode(user.id),
verification_key=user.verification_key)})
# TODO: There is no error handling in place
@@ -144,7 +144,7 @@ def send_fp_verification_email(user, request):
'verification_url': EMAIL_FP_VERIFICATION_TEMPLATE.format(
host=request.host,
uri=request.urlgen('mediagoblin.auth.verify_forgot_password'),
userid=unicode(user._id),
userid=unicode(user.id),
fp_verification_key=user.fp_verification_key)})
# TODO: There is no error handling in place

View File

@@ -90,7 +90,7 @@ def register(request):
user.save(validate=True)
# log the user in
request.session['user_id'] = unicode(user._id)
request.session['user_id'] = unicode(user.id)
request.session.save()
# send verification email
@@ -125,7 +125,7 @@ def login(request):
if user and user.check_login(request.form['password']):
# set up login in session
request.session['user_id'] = unicode(user._id)
request.session['user_id'] = unicode(user.id)
request.session.save()
if request.form.get('next'):
@@ -167,7 +167,7 @@ def verify_email(request):
return render_404(request)
user = request.db.User.find_one(
{'_id': ObjectId(unicode(request.GET['userid']))})
{'id': ObjectId(unicode(request.GET['userid']))})
if user and user.verification_key == unicode(request.GET['token']):
user.status = u'active'
@@ -308,7 +308,7 @@ def verify_forgot_password(request):
# check if it's a valid Id
try:
user = request.db.User.find_one(
{'_id': ObjectId(unicode(formdata_userid))})
{'id': ObjectId(unicode(formdata_userid))})
except InvalidId:
return render_404(request)