Remove ObjectId from the tree
This was one of the last remaining Mongo holdouts and has been removed from the tree herewith. Good bye, ObjectId. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
c338ed34fa
commit
71717fd531
@ -21,17 +21,8 @@ calm the rest of the code base. Or provide super minimal
|
|||||||
implementations.
|
implementations.
|
||||||
|
|
||||||
Currently:
|
Currently:
|
||||||
- ObjectId "class": It's a function mostly doing
|
|
||||||
int(init_arg) to convert string primary keys into
|
|
||||||
integer primary keys.
|
|
||||||
- DESCENDING "constant"
|
- DESCENDING "constant"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
DESCENDING = object() # a unique object for this "constant"
|
DESCENDING = object() # a unique object for this "constant"
|
||||||
|
|
||||||
|
|
||||||
def ObjectId(value=None):
|
|
||||||
if value is None:
|
|
||||||
return None
|
|
||||||
return int(value)
|
|
||||||
|
@ -15,6 +15,6 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#TODO: check now after mongo removal if we can't rip out a layer of abstraction
|
#TODO: check now after mongo removal if we can't rip out a layer of abstraction
|
||||||
from mediagoblin.db.sql.fake import ObjectId, DESCENDING
|
from mediagoblin.db.sql.fake import DESCENDING
|
||||||
from mediagoblin.db.sql.util import atomic_update, check_media_slug_used, \
|
from mediagoblin.db.sql.util import atomic_update, check_media_slug_used, \
|
||||||
media_entries_for_tag_slug, check_collection_slug_used
|
media_entries_for_tag_slug, check_collection_slug_used
|
||||||
|
@ -20,8 +20,7 @@ from urlparse import urljoin
|
|||||||
from werkzeug.exceptions import Forbidden
|
from werkzeug.exceptions import Forbidden
|
||||||
from werkzeug.urls import url_quote
|
from werkzeug.urls import url_quote
|
||||||
|
|
||||||
from mediagoblin.db.util import ObjectId
|
from mediagoblin.db.sql.models import MediaEntry, User
|
||||||
from mediagoblin.db.sql.models import User
|
|
||||||
from mediagoblin.tools.response import redirect, render_404
|
from mediagoblin.tools.response import redirect, render_404
|
||||||
|
|
||||||
|
|
||||||
@ -70,8 +69,7 @@ def user_may_delete_media(controller):
|
|||||||
"""
|
"""
|
||||||
@wraps(controller)
|
@wraps(controller)
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
uploader_id = request.db.MediaEntry.find_one(
|
uploader_id = MediaEntry.query.get(request.matchdict['media']).uploader
|
||||||
{'id': ObjectId(request.matchdict['media'])}).uploader
|
|
||||||
if not (request.user.is_admin or
|
if not (request.user.is_admin or
|
||||||
request.user.id == uploader_id):
|
request.user.id == uploader_id):
|
||||||
raise Forbidden()
|
raise Forbidden()
|
||||||
@ -132,12 +130,12 @@ def get_user_media_entry(controller):
|
|||||||
'state': u'processed',
|
'state': u'processed',
|
||||||
'uploader': user.id})
|
'uploader': user.id})
|
||||||
|
|
||||||
# no media via slug? Grab it via ObjectId
|
# no media via slug? Grab it via object id
|
||||||
if not media:
|
if not media:
|
||||||
media = request.db.MediaEntry.find_one(
|
media = MediaEntry.query.filter_by(
|
||||||
{'id': ObjectId(request.matchdict['media']),
|
id=request.matchdict['media'],
|
||||||
'state': u'processed',
|
state=u'processed',
|
||||||
'uploader': user.id})
|
uploader=user.id).first()
|
||||||
# Still no media? Okay, 404.
|
# Still no media? Okay, 404.
|
||||||
if not media:
|
if not media:
|
||||||
return render_404(request)
|
return render_404(request)
|
||||||
@ -206,9 +204,9 @@ def get_media_entry_by_id(controller):
|
|||||||
"""
|
"""
|
||||||
@wraps(controller)
|
@wraps(controller)
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
media = request.db.MediaEntry.find_one(
|
media = MediaEntry.query.filter_by(
|
||||||
{'id': ObjectId(request.matchdict['media']),
|
id=request.matchdict['media'],
|
||||||
'state': u'processed'})
|
state=u'processed').first()
|
||||||
# Still no media? Okay, 404.
|
# Still no media? Okay, 404.
|
||||||
if not media:
|
if not media:
|
||||||
return render_404(request)
|
return render_404(request)
|
||||||
|
@ -19,7 +19,7 @@ import logging
|
|||||||
from celery.task import Task
|
from celery.task import Task
|
||||||
|
|
||||||
from mediagoblin import mg_globals as mgg
|
from mediagoblin import mg_globals as mgg
|
||||||
from mediagoblin.db.util import ObjectId
|
from mediagoblin.db.sql.models import MediaEntry
|
||||||
from mediagoblin.processing import mark_entry_failed, BaseProcessingFail
|
from mediagoblin.processing import mark_entry_failed, BaseProcessingFail
|
||||||
from mediagoblin.tools.processing import json_processing_callback
|
from mediagoblin.tools.processing import json_processing_callback
|
||||||
|
|
||||||
@ -41,8 +41,7 @@ class ProcessMedia(Task):
|
|||||||
Pass the media entry off to the appropriate processing function
|
Pass the media entry off to the appropriate processing function
|
||||||
(for now just process_image...)
|
(for now just process_image...)
|
||||||
"""
|
"""
|
||||||
entry = mgg.database.MediaEntry.one(
|
entry = MediaEntry.query.get(media_id)
|
||||||
{'id': ObjectId(media_id)})
|
|
||||||
|
|
||||||
# Try to process, and handle expected errors.
|
# Try to process, and handle expected errors.
|
||||||
try:
|
try:
|
||||||
|
@ -40,7 +40,7 @@ class Pagination(object):
|
|||||||
- page: requested page
|
- page: requested page
|
||||||
- per_page: number of objects per page
|
- per_page: number of objects per page
|
||||||
- cursor: db cursor
|
- cursor: db cursor
|
||||||
- jump_to_id: ObjectId, sets the page to the page containing the
|
- jump_to_id: object id, sets the page to the page containing the
|
||||||
object with id == jump_to_id.
|
object with id == jump_to_id.
|
||||||
"""
|
"""
|
||||||
self.page = page
|
self.page = page
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from mediagoblin.db.util import ObjectId
|
from mediagoblin.db.sql.models import User
|
||||||
|
|
||||||
_log = logging.getLogger(__name__)
|
_log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import logging
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from mediagoblin import messages, mg_globals
|
from mediagoblin import messages, mg_globals
|
||||||
from mediagoblin.db.util import DESCENDING, ObjectId
|
from mediagoblin.db.util import DESCENDING
|
||||||
from mediagoblin.db.sql.models import (MediaEntry, Collection, CollectionItem,
|
from mediagoblin.db.sql.models import (MediaEntry, Collection, CollectionItem,
|
||||||
User)
|
User)
|
||||||
from mediagoblin.tools.response import render_to_response, render_404, redirect
|
from mediagoblin.tools.response import render_to_response, render_404, redirect
|
||||||
@ -116,7 +116,7 @@ def media_home(request, media, page, **kwargs):
|
|||||||
page, media.get_comments(
|
page, media.get_comments(
|
||||||
mg_globals.app_config['comments_ascending']),
|
mg_globals.app_config['comments_ascending']),
|
||||||
MEDIA_COMMENTS_PER_PAGE,
|
MEDIA_COMMENTS_PER_PAGE,
|
||||||
ObjectId(request.matchdict.get('comment')))
|
request.matchdict.get('comment'))
|
||||||
else:
|
else:
|
||||||
pagination = Pagination(
|
pagination = Pagination(
|
||||||
page, media.get_comments(
|
page, media.get_comments(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user