summaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2012-12-21 22:07:45 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2012-12-21 22:07:45 +0100
commite745764fc55043f6107f68986f82845310537fee (patch)
treeca8923d2b98f304759afa5799eebd25f129165d2 /app.py
parent1134dc1efa6a4326424cf7b1271cb4465afb712d (diff)
Added feedback and limits to searches.
Diffstat (limited to 'app.py')
-rwxr-xr-xapp.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/app.py b/app.py
index 8aecdf8..eb3e7da 100755
--- a/app.py
+++ b/app.py
@@ -59,6 +59,10 @@ class JSONApplication(object):
def search(self, environ, start_response, path):
args = cgi.FieldStorage(environ = environ)
query = args.getvalue('q')
+ if not (query or '').strip():
+ start_response('200 OK', [])
+ return json.dumps({'total': 0, 'results': []})
+
r = self.re_search.findall(query)
d = {}
l = []
@@ -69,16 +73,21 @@ class JSONApplication(object):
else:
l.append(v)
+ total_results = 0
results = []
try:
session = db.Session()
r = db.Track.search(session, *l, **d)
- results = [self.format_track(x) for x in r]
+ total_results = r.count()
+ results = [self.format_track(x) for x in r.limit(100)]
finally:
session.close()
start_response('200 OK', [])
- return json.dumps(results)
+ return json.dumps({
+ 'total': total_results,
+ 'results': results,
+ })
def albums(self, environ, start_response, path):
page = int(path[1] if len(path) > 1 else 0)