18
18
from nova import exception
21
def limited(items, req):
22
"""Return a slice of items according to requested offset and limit.
25
req - wobob.Request possibly containing offset and limit GET variables.
26
offset is where to start in the list, and limit is the maximum number
29
If limit is not specified, 0, or > 1000, defaults to 1000.
32
offset = int(req.GET.get('offset', 0))
33
limit = int(req.GET.get('limit', 0))
36
limit = min(1000, limit)
21
def limited(items, request, max_limit=1000):
23
Return a slice of items according to requested offset and limit.
25
@param items: A sliceable entity
26
@param request: `webob.Request` possibly containing 'offset' and 'limit'
27
GET variables. 'offset' is where to start in the list,
28
and 'limit' is the maximum number of items to return. If
29
'limit' is not specified, 0, or > max_limit, we default
31
@kwarg max_limit: The maximum number of items to return from 'items'
34
offset = int(request.GET.get('offset', 0))
39
limit = int(request.GET.get('limit', max_limit))
43
limit = min(max_limit, limit or max_limit)
37
44
range_end = offset + limit
38
45
return items[offset:range_end]