Skip to content

Commit

Permalink
add 'limit' parameter to location search
Browse files Browse the repository at this point in the history
  • Loading branch information
gasman committed Dec 4, 2011
1 parent 401b92e commit 8dc28e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/endpoints.txt
Expand Up @@ -14,6 +14,7 @@ Available API endpoints
lat / lng - if passed, locations are returned in ascending order of distance,
and include a 'distance_metres' field
max_distance - maximum distance in metres; lat/lng must also be passed
limit - maximum number of results to return

/api/{locale}/location/{id}/
details of the location with the specified ID
Expand Down
7 changes: 6 additions & 1 deletion backend/api/handlers.py
Expand Up @@ -63,7 +63,12 @@ def read(self, request, locale_slug):
if request.GET.get('max_distance'):
base = base.filter(point__distance_lte=(my_location, D(m=request.GET['max_distance'])))

return base.distinct()
results = base.distinct()

if request.GET.get('limit'):
results = results[:request.GET['limit']]

return results

class LocationHandler(BaseHandler):
allowed_methods = ('GET',)
Expand Down

0 comments on commit 8dc28e7

Please sign in to comment.