diff options
author | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2012-12-05 13:42:00 +0100 |
---|---|---|
committer | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2012-12-05 13:55:31 +0100 |
commit | e2ae0f59202e39f996cd796e42420e061eebf8d1 (patch) | |
tree | 2f8d4f0bebefd8896b8eed1f1e56210bdbeca59c /mediagoblin/user_pages/views.py | |
parent | 64c2a4002c261c01c50f333a8aa8dc5c223e79c9 (diff) | |
download | mediagoblin-e2ae0f59202e39f996cd796e42420e061eebf8d1.tar.lz mediagoblin-e2ae0f59202e39f996cd796e42420e061eebf8d1.tar.xz mediagoblin-e2ae0f59202e39f996cd796e42420e061eebf8d1.zip |
Fix user collection gallery
We were fetching the user collection gallery by slug only, so if two users
had the same collection slug, we would not have been sure which one we'd get.
Fix this by explicitly only fetching the specific user's collections. Also
switch over the view function to make use of the new active_user_from_url
decorator that fetches the User() object for us.
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Diffstat (limited to 'mediagoblin/user_pages/views.py')
-rw-r--r-- | mediagoblin/user_pages/views.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index e260a592..cbf3f15f 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -319,32 +319,28 @@ def media_confirm_delete(request, media): 'form': form}) +@active_user_from_url @uses_pagination -def user_collection(request, page): +def user_collection(request, page, url_user=None): """A User-defined Collection""" - user = request.db.User.find_one({ - 'username': request.matchdict['user'], - 'status': u'active'}) - if not user: - return render_404(request) + collection = Collection.query.filter_by( + get_creator=url_user, + slug=request.matchdict['collection']).first() - collection = request.db.Collection.find_one( - {'slug': request.matchdict['collection']}) - - cursor = request.db.CollectionItem.find( - {'collection': collection.id}) + cursor = collection.get_collection_items() pagination = Pagination(page, cursor) collection_items = pagination() - #if no data is available, return NotFound + # if no data is available, return NotFound + # TODO: Should an empty collection really also return 404? if collection_items == None: return render_404(request) return render_to_response( request, 'mediagoblin/user_pages/collection.html', - {'user': user, + {'user': url_user, 'collection': collection, 'collection_items': collection_items, 'pagination': pagination}) |