Factor out paging control
Closed this issue · 2 comments
gwk commented
I have created pithy/html/parts.py
, which has an unimplemented function pagination_control
. The implementation should be factored out from pithy.select
render_pagination_control
. The tricky part is that I do not want to use the QueryParams
type. Instead we should treat the params argument as a generic Mapping
. You should iterate over the items in the mapping, swapping in the new offset.
Something like:
from url lib.parse import urlencode
page_params = dict(params)
page_params['offset'] = offset
href = f'?{urlencode(tuple((k, str(v)) for k, v in params.items()))}'
That last line was copied from pithy.url.fmt_url, which might serve as a reference to play with if something doesn't seem right.