implementations.
Currently:
-- ObjectId "class": It's a function mostly doing
- int(init_arg) to convert string primary keys into
- integer primary keys.
- DESCENDING "constant"
"""
DESCENDING = object() # a unique object for this "constant"
-
-
-def ObjectId(value=None):
- if value is None:
- return None
- return int(value)
# 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
-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, \
media_entries_for_tag_slug, check_collection_slug_used
from werkzeug.exceptions import Forbidden
from werkzeug.urls import url_quote
-from mediagoblin.db.util import ObjectId
-from mediagoblin.db.sql.models import User
+from mediagoblin.db.sql.models import MediaEntry, User
from mediagoblin.tools.response import redirect, render_404
"""
@wraps(controller)
def wrapper(request, *args, **kwargs):
- uploader_id = request.db.MediaEntry.find_one(
- {'id': ObjectId(request.matchdict['media'])}).uploader
+ uploader_id = MediaEntry.query.get(request.matchdict['media']).uploader
if not (request.user.is_admin or
request.user.id == uploader_id):
raise Forbidden()
'state': u'processed',
'uploader': user.id})
- # no media via slug? Grab it via ObjectId
+ # no media via slug? Grab it via object id
if not media:
- media = request.db.MediaEntry.find_one(
- {'id': ObjectId(request.matchdict['media']),
- 'state': u'processed',
- 'uploader': user.id})
+ media = MediaEntry.query.filter_by(
+ id=request.matchdict['media'],
+ state=u'processed',
+ uploader=user.id).first()
# Still no media? Okay, 404.
if not media:
return render_404(request)
"""
@wraps(controller)
def wrapper(request, *args, **kwargs):
- media = request.db.MediaEntry.find_one(
- {'id': ObjectId(request.matchdict['media']),
- 'state': u'processed'})
+ media = MediaEntry.query.filter_by(
+ id=request.matchdict['media'],
+ state=u'processed').first()
# Still no media? Okay, 404.
if not media:
return render_404(request)
from celery.task import Task
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.tools.processing import json_processing_callback
Pass the media entry off to the appropriate processing function
(for now just process_image...)
"""
- entry = mgg.database.MediaEntry.one(
- {'id': ObjectId(media_id)})
+ entry = MediaEntry.query.get(media_id)
# Try to process, and handle expected errors.
try:
- page: requested page
- per_page: number of objects per page
- 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.
"""
self.page = page
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
-from mediagoblin.db.util import ObjectId
+from mediagoblin.db.sql.models import User
_log = logging.getLogger(__name__)
import datetime
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,
User)
from mediagoblin.tools.response import render_to_response, render_404, redirect
page, media.get_comments(
mg_globals.app_config['comments_ascending']),
MEDIA_COMMENTS_PER_PAGE,
- ObjectId(request.matchdict.get('comment')))
+ request.matchdict.get('comment'))
else:
pagination = Pagination(
page, media.get_comments(