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:
@@ -17,7 +17,7 @@
|
||||
|
||||
def may_edit_media(request, media):
|
||||
"""Check, if the request's user may edit the media details"""
|
||||
if media.uploader == request.user._id:
|
||||
if media.uploader == request.user.id:
|
||||
return True
|
||||
if request.user.is_admin:
|
||||
return True
|
||||
|
||||
@@ -79,7 +79,7 @@ def edit_media(request, media):
|
||||
location=media.url_for_self(request.urlgen))
|
||||
|
||||
if request.user.is_admin \
|
||||
and media.uploader != request.user._id \
|
||||
and media.uploader != request.user.id \
|
||||
and request.method != 'POST':
|
||||
messages.add_message(
|
||||
request, messages.WARNING,
|
||||
@@ -130,7 +130,7 @@ def edit_attachments(request, media):
|
||||
|
||||
attachment_public_filepath \
|
||||
= mg_globals.public_store.get_unique_filepath(
|
||||
['media_entries', unicode(media._id), 'attachment',
|
||||
['media_entries', unicode(media.id), 'attachment',
|
||||
public_filename])
|
||||
|
||||
attachment_public_file = mg_globals.public_store.get_file(
|
||||
@@ -278,7 +278,7 @@ def edit_collection(request, collection):
|
||||
|
||||
# Make sure there isn't already a Collection with this title
|
||||
existing_collection = request.db.Collection.find_one({
|
||||
'creator': request.user._id,
|
||||
'creator': request.user.id,
|
||||
'title':request.form['title']})
|
||||
|
||||
if existing_collection and existing_collection.id != collection.id:
|
||||
@@ -301,7 +301,7 @@ def edit_collection(request, collection):
|
||||
collection=collection.slug)
|
||||
|
||||
if request.user.is_admin \
|
||||
and collection.creator != request.user._id \
|
||||
and collection.creator != request.user.id \
|
||||
and request.method != 'POST':
|
||||
messages.add_message(
|
||||
request, messages.WARNING,
|
||||
|
||||
Reference in New Issue
Block a user