From ee1df842f7328fbe7f9a2b9d402b15f5d0895a72 Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 13 Nov 2021 23:15:21 +0100 Subject: [PATCH] replace querystring_page() by jinja2 code inside the macro removes handling of obsolete special cases and prev-page-handling. also remove back button from subscriptions page, since nothing else uses that feaure any more. note: {% set _nil = ... %} simulates a {% do ... %} expression, which isn't available by default in flask's jinja config. --- app/__init__.py | 18 ------------------ app/templates/macros.imp.j2 | 5 ++++- app/youtube/templates/index.html.j2 | 7 +------ 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 80da7bf..bd3d9b3 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -15,24 +15,6 @@ for name in cf['frontend']['modules'].split(','): blueprint = importlib.import_module('.'+name, __name__) app.register_blueprint(blueprint.frontend) -# TODO: move this somewhere else -@app.template_global() -def querystring_page(fields): - def try_int(i): - try: return int(i) - except: return None - tmp = dict(request.args) - for field,what in fields.items(): - if type(what) is tuple: - (plusminus, default) = what - tmp[field] = (try_int(tmp.get(field)) or int(default)) + plusminus - elif type(what) is type(None): - if field in tmp: del tmp[field] - else: - tmp[field] = what - from werkzeug.urls import url_encode - return url_encode(tmp) - # TODO: should this go somewhere else? # This error handler logs requests to external apis, and POST data. this makes debugging of api responses easier, as the request can be reconstructed and replayed. from flask import g, request diff --git a/app/templates/macros.imp.j2 b/app/templates/macros.imp.j2 index 5d64aa4..530d8f0 100644 --- a/app/templates/macros.imp.j2 +++ b/app/templates/macros.imp.j2 @@ -132,5 +132,8 @@ {%- endmacro %} {% macro pagination(text, fields, direction) -%} - + {% set request_args = dict(request.args) %} + {% set _nil = request_args.update(fields) %} + {% set new_qs = request_args|urlencode %} + {%- endmacro %} diff --git a/app/youtube/templates/index.html.j2 b/app/youtube/templates/index.html.j2 index c9ce23d..351edd9 100644 --- a/app/youtube/templates/index.html.j2 +++ b/app/youtube/templates/index.html.j2 @@ -18,12 +18,7 @@ {% if not rows|length %}no more results{% endif %}
-{% if page > 0 %} -{{ macros.pagination("newer", {'page':(-1,0)}, -1) }} -{% endif %} -{% if rows|length %} -{{ macros.pagination("older", {'page':(+1,0)}, +1) }} -{% endif %} + {{ macros.pagination("more", {'page':page+1}, +1) if rows|length }}
{% endblock %} -- 2.39.3