Merge lp:~dholbach/harvest/974431 into lp:harvest

Proposed by Daniel Holbach on 2012-04-11
Status: Merged
Merged at revision: 330
Proposed branch: lp:~dholbach/harvest/974431
Merge into: lp:harvest
Diff against target: 24 lines (+6/-4) 1 file modified
To merge this branch: bzr merge lp:~dholbach/harvest/974431
Reviewer Review Type Date Requested Status
harvest-dev 2012-04-11 Pending
Review via email: mp+101543@code.launchpad.net

This proposal supersedes a proposal from 2012-04-10.

Description of the Change

The API now does slicing and sorting now properly.

Test-case:
wget -O - "http://127.0.0.1:8000/services/sourcepackages/?_sortby=id"
wget -O - "http://127.0.0.1:8000/services/sourcepackages/?_offset=500&_sortby=id"

To post a comment you must log in.
Michael Hall (mhall119) wrote : Posted in a previous version of this proposal

Looks good to me

review: Approve

Preview Diff

1=== modified file 'harvest/services/__init__.py'
2--- harvest/services/__init__.py 2010-12-08 08:15:50 +0000
3+++ harvest/services/__init__.py 2012-04-11 12:36:17 +0000
4@@ -80,14 +80,16 @@
5 for key in search_values.keys():
6 if key.startswith('_'):
7 extra_arguments[key] = search_values.pop(key)
8+ if '_sortby' in request and request['_sortby'] not in EMPTY_VALUES:
9+ results = model.objects.filter(**search_values).order_by(request.get('_sortby'))
10+
11 offset = parse_number_argument(extra_arguments, '_offset')
12 length = parse_number_argument(extra_arguments, '_length')
13+ start = offset if offset else 0
14 if not length or length > CHUNK_SIZE:
15 length = CHUNK_SIZE
16- results = model.objects.filter(**search_values)[offset:length]
17-
18- if '_sortby' in request and request['_sortby'] not in EMPTY_VALUES:
19- results = results.order_by(request.get('_sortby'))
20+ end = start + length
21+ results = results[start:end]
22 return results
23
24 def get_model_id(request, url):

Subscribers

People subscribed via source and target branches

to all changes: