From c87233a1556ca56fd62d51b395bbb6a305664101 Mon Sep 17 00:00:00 2001 From: lemon24 Date: Sat, 12 Mar 2022 01:11:33 +0200 Subject: [PATCH] Allow editing entry/global tags in the web app. For #272. --- CHANGES.rst | 4 ++ src/reader/_app/__init__.py | 48 +++++++++++++++++------- src/reader/_app/templates/entry.html | 3 ++ src/reader/_app/templates/layout.html | 1 + src/reader/_app/templates/metadata.html | 49 ++++++++++++++++++++++--- 5 files changed, 87 insertions(+), 18 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3b7cab95..a334b766 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -29,6 +29,10 @@ Unreleased * Remove the ``global_metadata`` experimental plugin (superseded by global tags). +* In the web application, support editing entry and global metadata. + Fix broken delete metadata button. + Fix broken error flashing. + Version 2.9 ----------- diff --git a/src/reader/_app/__init__.py b/src/reader/_app/__init__.py index bd9b2bfe..9fa1efe6 100644 --- a/src/reader/_app/__init__.py +++ b/src/reader/_app/__init__.py @@ -505,12 +505,22 @@ def fancy_sort_key(data): def metadata(): reader = get_reader() - feed_url = request.args['feed'] - feed = reader.get_feed(feed_url, None) - if not feed: - abort(404) + feed = entry = None + if 'feed' in request.args: + if 'entry' not in request.args: + resource_id = request.args['feed'] + feed = reader.get_feed(resource_id, None) + else: + resource_id = request.args['feed'], request.args['entry'] + entry = reader.get_entry(resource_id, None) + if entry: + feed = entry.feed + if not feed: + abort(404) + else: + resource_id = () - metadata = reader.get_tags(feed_url) + metadata = reader.get_tags(resource_id) # Ensure flashed messages get removed from the session. # https://github.com/lemon24/reader/issues/81 @@ -519,6 +529,7 @@ def metadata(): return stream_template( 'metadata.html', feed=feed, + entry=entry, metadata=metadata, to_pretty_json=lambda t: yaml.safe_dump(t), ) @@ -665,32 +676,43 @@ def update_feed_title(data): get_reader().set_feed_user_title(feed_url, feed_title) +def _resource_id_from_data(data): + rv = () + if 'feed-url' in data: + rv += (data['feed-url'],) + if 'entry-id' in data: + rv += (data['entry-id'],) + return rv + + @form_api @readererror_to_apierror() def add_metadata(data): - feed_url = data['feed-url'] + resource_id = _resource_id_from_data(data) key = data['key'] - get_reader().set_tag(feed_url, key, None) + get_reader().set_tag(resource_id, key, None) @form_api @readererror_to_apierror() def update_metadata(data): - feed_url = data['feed-url'] + resource_id = _resource_id_from_data(data) key = data['key'] try: value = yaml.safe_load(data['value']) except yaml.YAMLError as e: - raise APIError("invalid JSON: {}".format(e), (feed_url, key)) from e - get_reader().set_tag(feed_url, key, value) + raise APIError("invalid JSON: {}".format(e), resource_id + (key,)) from e + get_reader().set_tag(resource_id, key, value) -@form_api(really=True) +# TODO: @form_api(really=True) +@form_api @readererror_to_apierror() def delete_metadata(data): - feed_url = data['feed-url'] + resource_id = _resource_id_from_data(data) + print(resource_id) key = data['key'] - get_reader().delete_tag(feed_url, key) + get_reader().delete_tag(resource_id, key) @form_api diff --git a/src/reader/_app/templates/entry.html b/src/reader/_app/templates/entry.html index 0f4ad734..04b4bbd5 100644 --- a/src/reader/_app/templates/entry.html +++ b/src/reader/_app/templates/entry.html @@ -47,6 +47,9 @@ {{ macros.confirm_button('.form_api', 'delete-entry', 'delete', leave_disabled=true, next=url_for('.entries', **request.args), context=context) }} {% endif %} +
  • +update metadata + {% if content %} {% set minutes = read_time(content).minutes %} {% if minutes > 1 %} diff --git a/src/reader/_app/templates/layout.html b/src/reader/_app/templates/layout.html index 58aad6ef..3f4c4085 100644 --- a/src/reader/_app/templates/layout.html +++ b/src/reader/_app/templates/layout.html @@ -20,6 +20,7 @@ entries feeds tags +metadata {{ macros.text_input_button_get( 'reader.preview', 'add feed', 'url', 'url', diff --git a/src/reader/_app/templates/metadata.html b/src/reader/_app/templates/metadata.html index 183d4c0a..d26e33b2 100644 --- a/src/reader/_app/templates/metadata.html +++ b/src/reader/_app/templates/metadata.html @@ -2,8 +2,26 @@ {% import "macros.html" as macros %} -{% block page_title %}Metadata for {{ macros.feed_title(feed) }}{% endblock %} -{% block main_title %}Metadata for {{ macros.feed_title(feed) }}{% endblock %} + +{% macro make_title() %} + {% if feed %} + {% if not entry %} + Metadata for + + {{ macros.feed_title(feed) }} + {% else %} + Metadata for + + {{ entry.title or "untitled" }} + {% endif %} + {% else %} + Global metadata + {% endif %} +{% endmacro %} + +{% block page_title %}{{ make_title() | striptags }}{% endblock %} +{% block main_title %}{{ make_title() }}{% endblock %} {% block body %} @@ -13,14 +31,30 @@
    +{% if feed %} +{% if entry %} + +{% endif %} +{% endif %}
    +