From 547699a9fc00c2f571ea5de4b423f8849022131c Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Mon, 19 Jun 2023 15:15:03 -0700 Subject: [PATCH] Add links to show/hide hidden items --- intake/app.py | 42 ++++++++++++++++++++++++++++-------- intake/templates/feed.jinja2 | 22 +++++++++++++------ 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/intake/app.py b/intake/app.py index a1b3af7..bb47154 100644 --- a/intake/app.py +++ b/intake/app.py @@ -29,6 +29,19 @@ def item_sort_key(item: Item): return item.sort_key +def get_show_hidden(default: bool): + """ + Get the value of the ?hidden query parameter, with a default value if it is + absent or set to an unnown value. + """ + hidden = request.args.get("hidden") + if hidden == "true": + return True + if hidden == "false": + return False + return default + + @app.template_filter("datetimeformat") def datetimeformat(value): if not value: @@ -37,6 +50,20 @@ def datetimeformat(value): return dt.strftime("%Y-%m-%d %H:%M:%S") +@app.template_global() +def set_query(**kwargs): + """ + Helper function to create a URL plus or minus some query parameters. + """ + args = request.args.copy() + for key, val in kwargs.items(): + if val is None and key in args: + del args[key] + else: + args[key] = val + return url_for(request.endpoint, **request.view_args, **args) + + def auth_check(route): """ Checks the HTTP Basic Auth header against the stored credential. @@ -95,7 +122,7 @@ def source_feed(name): if not source.source_path.exists(): abort(404) - return _sources_feed(name, [source], show_hidden=request.args.get("hidden", True)) + return _sources_feed(name, [source], show_hidden=get_show_hidden(True)) @app.get("/channel/") @@ -112,7 +139,7 @@ def channel_feed(name): abort(404) sources = [LocalSource(intake_data_dir(), name) for name in channels[name]] - return _sources_feed(name, sources, show_hidden=request.args.get("hidden", False)) + return _sources_feed(name, sources, show_hidden=get_show_hidden(False)) def _sources_feed(name: str, sources: List[LocalSource], show_hidden: bool): @@ -154,8 +181,9 @@ def _sources_feed(name: str, sources: List[LocalSource], show_hidden: bool): for item in paged_items if "id" in item ], - pager_prev=pager_prev, - pager_next=pager_next, + page_num=page, + page_count=count, + item_count=len(all_items), ) @@ -340,11 +368,7 @@ def add_item(): if form_body := request.form.get("body"): fields["body"] = form_body if form_tags := request.form.get("tags"): - fields["tags"] = [ - tag.strip() - for tag in form_tags.split() - if tag.strip() - ] + fields["tags"] = [tag.strip() for tag in form_tags.split() if tag.strip()] if form_tts := request.form.get("tts"): fields["tts"] = _get_ttx_for_date(datetime.fromisoformat(form_tts)) if form_ttl := request.form.get("ttl"): diff --git a/intake/templates/feed.jinja2 b/intake/templates/feed.jinja2 index de79ee4..919120e 100644 --- a/intake/templates/feed.jinja2 +++ b/intake/templates/feed.jinja2 @@ -57,7 +57,7 @@ pre { table.feed-control td { font-family: monospace; padding: 5px 10px; } -div.center { +article.center { text-align: center; } @@ -122,7 +122,15 @@ var doAction = function (source, itemid, action) {
{% if items %} {% for item in items %} @@ -176,18 +184,18 @@ var doAction = function (source, itemid, action) { {% endfor %} -{% if pager_prev or pager_next %} +{% if item_count > items|length %} {% endif %} -
-
+
-
{# if items #}