Generalize pagination with custom Jinja2 macro