From: Sebastian Spaeth Date: Wed, 5 Dec 2012 12:38:50 +0000 (+0100) Subject: Switch over the user gallery to the active_user_from_url decorator X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=64c2a4002c261c01c50f333a8aa8dc5c223e79c9;p=mediagoblin.git Switch over the user gallery to the active_user_from_url decorator This switches the user gallery page over to use the new decorator, and cleans up the queries to be in proper sqlalchemy format rather than the old mongo format. Signed-off-by: Sebastian Spaeth --- diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index ec159b6e..e260a592 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -20,6 +20,7 @@ import datetime from mediagoblin import messages, mg_globals from mediagoblin.db.util import DESCENDING, ObjectId +from mediagoblin.db.sql.models import MediaEntry, Collection, CollectionItem from mediagoblin.tools.response import render_to_response, render_404, redirect from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.pagination import Pagination @@ -29,7 +30,7 @@ from mediagoblin.user_pages.lib import send_comment_email from mediagoblin.decorators import (uses_pagination, get_user_media_entry, require_active_login, user_may_delete_media, user_may_alter_collection, - get_user_collection, get_user_collection_item) + get_user_collection, get_user_collection_item, active_user_from_url) from werkzeug.contrib.atom import AtomFeed @@ -75,30 +76,26 @@ def user_home(request, page): 'pagination': pagination}) +@active_user_from_url @uses_pagination -def user_gallery(request, page): +def user_gallery(request, page, url_user=None): """'Gallery' of a User()""" - user = request.db.User.find_one({ - 'username': request.matchdict['user'], - 'status': u'active'}) - if not user: - return render_404(request) - - cursor = request.db.MediaEntry.find( - {'uploader': user._id, - 'state': u'processed'}).sort('created', DESCENDING) - + cursor = MediaEntry.query.filter_by( + uploader=url_user.id, + state=u'processed').order_by(MediaEntry.created.desc()) + # Paginate gallery pagination = Pagination(page, cursor) media_entries = pagination() #if no data is available, return NotFound + # TODO: Should we really also return 404 for empty galleries? if media_entries == None: return render_404(request) return render_to_response( request, 'mediagoblin/user_pages/gallery.html', - {'user': user, + {'user': url_user, 'media_entries': media_entries, 'pagination': pagination})