Remove mediagoblin.db.sql.fake.DESCENDING
This is the last remnant that requires us to keep db.sql.fake.py. Use ModelName.desc() or sqlalchemy.sql.expression.desc(column) to achieve descending sorts. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
208842590c
commit
0efe9e2796
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
from werkzeug.exceptions import Forbidden
|
from werkzeug.exceptions import Forbidden
|
||||||
|
|
||||||
from mediagoblin.db.util import DESCENDING
|
from mediagoblin.db.sql.models import MediaEntry
|
||||||
from mediagoblin.decorators import require_active_login
|
from mediagoblin.decorators import require_active_login
|
||||||
from mediagoblin.tools.response import render_to_response
|
from mediagoblin.tools.response import render_to_response
|
||||||
|
|
||||||
@ -29,15 +29,15 @@ def admin_processing_panel(request):
|
|||||||
if not request.user.is_admin:
|
if not request.user.is_admin:
|
||||||
raise Forbidden()
|
raise Forbidden()
|
||||||
|
|
||||||
processing_entries = request.db.MediaEntry.find(
|
processing_entries = MediaEntry.query.filter_by(state = u'processing').\
|
||||||
{'state': u'processing'}).sort('created', DESCENDING)
|
order_by(MediaEntry.created.desc())
|
||||||
|
|
||||||
# Get media entries which have failed to process
|
# Get media entries which have failed to process
|
||||||
failed_entries = request.db.MediaEntry.find(
|
failed_entries = MediaEntry.query.filter_by(state = u'failed').\
|
||||||
{'state': u'failed'}).sort('created', DESCENDING)
|
order_by(MediaEntry.created.desc())
|
||||||
|
|
||||||
processed_entries = request.db.MediaEntry.find(
|
processed_entries = MediaEntry.query.filter_by(state = u'processed').\
|
||||||
{'state': u'processed'}).sort('created', DESCENDING).limit(10)
|
order_by(MediaEntry.created.desc()).limit(10)
|
||||||
|
|
||||||
# Render to response
|
# Render to response
|
||||||
return render_to_response(
|
return render_to_response(
|
||||||
|
@ -18,9 +18,6 @@
|
|||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import scoped_session, sessionmaker, object_session
|
from sqlalchemy.orm import scoped_session, sessionmaker, object_session
|
||||||
from sqlalchemy.orm.query import Query
|
from sqlalchemy.orm.query import Query
|
||||||
from sqlalchemy.sql.expression import desc
|
|
||||||
from mediagoblin.db.sql.fake import DESCENDING
|
|
||||||
|
|
||||||
|
|
||||||
def _get_query_model(query):
|
def _get_query_model(query):
|
||||||
cols = query.column_descriptions
|
cols = query.column_descriptions
|
||||||
@ -29,10 +26,8 @@ def _get_query_model(query):
|
|||||||
|
|
||||||
|
|
||||||
class GMGQuery(Query):
|
class GMGQuery(Query):
|
||||||
def sort(self, key, direction):
|
def sort(self, key):
|
||||||
key_col = getattr(_get_query_model(self), key)
|
key_col = getattr(_get_query_model(self), key)
|
||||||
if direction is DESCENDING:
|
|
||||||
key_col = desc(key_col)
|
|
||||||
return self.order_by(key_col)
|
return self.order_by(key_col)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
This module contains some fake classes and functions to
|
|
||||||
calm the rest of the code base. Or provide super minimal
|
|
||||||
implementations.
|
|
||||||
|
|
||||||
Currently:
|
|
||||||
- DESCENDING "constant"
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
DESCENDING = object() # a unique object for this "constant"
|
|
@ -15,6 +15,5 @@
|
|||||||
# 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 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
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from mediagoblin.db.util import media_entries_for_tag_slug, DESCENDING
|
from mediagoblin.db.sql.models import MediaEntry
|
||||||
|
from mediagoblin.db.util import media_entries_for_tag_slug
|
||||||
from mediagoblin.tools.pagination import Pagination
|
from mediagoblin.tools.pagination import Pagination
|
||||||
from mediagoblin.tools.response import render_to_response
|
from mediagoblin.tools.response import render_to_response
|
||||||
from mediagoblin.decorators import uses_pagination
|
from mediagoblin.decorators import uses_pagination
|
||||||
@ -45,7 +45,7 @@ def tag_listing(request, page):
|
|||||||
tag_slug = request.matchdict[u'tag']
|
tag_slug = request.matchdict[u'tag']
|
||||||
|
|
||||||
cursor = media_entries_for_tag_slug(request.db, tag_slug)
|
cursor = media_entries_for_tag_slug(request.db, tag_slug)
|
||||||
cursor = cursor.sort('created', DESCENDING)
|
cursor = cursor.order_by(MediaEntry.created.desc())
|
||||||
|
|
||||||
pagination = Pagination(page, cursor)
|
pagination = Pagination(page, cursor)
|
||||||
media_entries = pagination()
|
media_entries = pagination()
|
||||||
@ -71,7 +71,7 @@ def tag_atom_feed(request):
|
|||||||
tag_slug = request.matchdict[u'tag']
|
tag_slug = request.matchdict[u'tag']
|
||||||
|
|
||||||
cursor = media_entries_for_tag_slug(request.db, tag_slug)
|
cursor = media_entries_for_tag_slug(request.db, tag_slug)
|
||||||
cursor = cursor.sort('created', DESCENDING)
|
cursor = cursor.order_by(MediaEntry.created.desc())
|
||||||
cursor = cursor.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
|
cursor = cursor.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -18,7 +18,6 @@ import logging
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from mediagoblin import messages, mg_globals
|
from mediagoblin import messages, mg_globals
|
||||||
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
|
||||||
@ -56,7 +55,7 @@ def user_home(request, page):
|
|||||||
|
|
||||||
cursor = MediaEntry.query.\
|
cursor = MediaEntry.query.\
|
||||||
filter_by(uploader = user.id,
|
filter_by(uploader = user.id,
|
||||||
state = u'processed').sort('created', DESCENDING)
|
state = u'processed').order_by(MediaEntry.created.desc())
|
||||||
|
|
||||||
pagination = Pagination(page, cursor)
|
pagination = Pagination(page, cursor)
|
||||||
media_entries = pagination()
|
media_entries = pagination()
|
||||||
@ -449,7 +448,7 @@ def atom_feed(request):
|
|||||||
cursor = MediaEntry.query.filter_by(
|
cursor = MediaEntry.query.filter_by(
|
||||||
uploader = user.id,
|
uploader = user.id,
|
||||||
state = u'processed').\
|
state = u'processed').\
|
||||||
sort('created', DESCENDING).\
|
order_by(MediaEntry.created.desc()).\
|
||||||
limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
|
limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -15,17 +15,17 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
|
from mediagoblin.db.sql.models import MediaEntry
|
||||||
from mediagoblin.tools.pagination import Pagination
|
from mediagoblin.tools.pagination import Pagination
|
||||||
from mediagoblin.tools.response import render_to_response
|
from mediagoblin.tools.response import render_to_response
|
||||||
from mediagoblin.db.util import DESCENDING
|
|
||||||
from mediagoblin.decorators import uses_pagination
|
from mediagoblin.decorators import uses_pagination
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@uses_pagination
|
@uses_pagination
|
||||||
def root_view(request, page):
|
def root_view(request, page):
|
||||||
cursor = request.db.MediaEntry.find(
|
cursor = MediaEntry.query.filter_by(state=u'processed').\
|
||||||
{u'state': u'processed'}).sort('created', DESCENDING)
|
order_by(MediaEntry.created.desc())
|
||||||
|
|
||||||
pagination = Pagination(page, cursor)
|
pagination = Pagination(page, cursor)
|
||||||
media_entries = pagination()
|
media_entries = pagination()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user