From c92aa0d0b21e01223db7eeaa2fcea4d961b512d9 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sat, 15 Sep 2012 22:34:34 +0200 Subject: [PATCH] API: Fixed media file URLs, limits - Added default limit and limit arg to get_entries - Fixed URL generation for BasicFileStorage files in API --- mediagoblin/plugins/api/tools.py | 12 ++++++++---- mediagoblin/plugins/api/views.py | 7 +++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/mediagoblin/plugins/api/tools.py b/mediagoblin/plugins/api/tools.py index 5488e515..e5aca29b 100644 --- a/mediagoblin/plugins/api/tools.py +++ b/mediagoblin/plugins/api/tools.py @@ -19,6 +19,7 @@ import json from functools import wraps from webob import exc, Response +from urlparse import urljoin from mediagoblin import mg_globals from mediagoblin.tools.pluginapi import PluginManager @@ -106,13 +107,16 @@ def get_media_file_paths(media_files, urlgen): filepath` pairs. :param urlgen: An urlgen object, usually found on request.urlgen. ''' - if isinstance(mg_globals.public_store, BasicFileStorage): - pass # TODO - media_urls = {} for key, val in media_files.items(): - media_urls[key] = mg_globals.public_store.file_url(val) + if isinstance(mg_globals.public_store, BasicFileStorage): + # BasicFileStorage does not provide a qualified URI + media_urls[key] = urljoin( + urlgen('index', qualified=True), + mg_globals.public_store.file_url(val)) + else: + media_urls[key] = mg_globals.public_store.file_url(val) return media_urls diff --git a/mediagoblin/plugins/api/views.py b/mediagoblin/plugins/api/views.py index ff177e29..2eb9e414 100644 --- a/mediagoblin/plugins/api/views.py +++ b/mediagoblin/plugins/api/views.py @@ -129,8 +129,15 @@ def api_test(request): def get_entries(request): entries = request.db.MediaEntry.query + # TODO: Make it possible to fetch unprocessed media, or media in-processing entries = entries.filter_by(state=u'processed') + # TODO: Add sort order customization + entries = entries.order_by(request.db.MediaEntry.created.desc()) + + # TODO: Fetch default and upper limit from config + entries = entries.limit(int(request.GET.get('limit') or 10)) + entries_serializable = [] for entry in entries: -- 2.25.1