codeforamerica/cfapi — pull request #105 by carpeliam (2014-07-18 03:12:35+00:00)
Title: when per_page is set, show it in the 'pages' response; fixes #104

When a `per_page` query parameter is set, it needs to be included in the `pages` section of the response. This addresses #104.

Feel free to change this around before accepting it if you're not happy with the style... I'm not a native pythonista, and I couldn't come up with a way I thought was better. My first pass was more along the lines of:

```python
if page > 1:
if 'per_page' in request.args:
pages['first'] = '%s?per_page=%s' % (url, request.args['per_page'])
else:
pages['first'] = url

if page == 2:
if 'per_page' in request.args:
pages['prev'] = '%s?per_page=%s' % (url, request.args['per_page'])
else:
pages['prev'] = url
elif page > 2:
if 'per_page' in request.args:
pages['prev'] = '%s?page=%d&per_page=%s' % (url, page - 1, request.args['per_page'])
else:
pages['prev'] = '%s?' % (url, page - 1)

if page < last:
if 'per_page' in request.args:
pages['next'] = '%s?page=%d&per_page=%s' % (url, page + 1, request.args['per_page'])
pages['last'] = '%s?page=%d&per_page=%s' % (url, last, request.args['per_page'])
else:
pages['next'] = '%s?page=%d' % (url, page + 1)
pages['last'] = '%s?page=%d' % (url, last)
```
...which I thought was harder to read.