From a45bcb74dde80ee576bfcbc2f3efb719e8f6b2d9 Mon Sep 17 00:00:00 2001 From: Arjun Satarkar Date: Thu, 3 Aug 2023 17:38:50 -0400 Subject: Allow setting custom title on /add_feed, improve form layout --- README.md | 2 +- serve.py | 13 ++++++------- static/styles/main.css | 32 ++++++++++++++++++++++++++------ tagrss.py | 20 ++++++++++++++------ views/add_feed.tpl | 20 ++++++++++---------- views/manage_feed.tpl | 16 +++++++++------- views/tag_input.tpl | 5 ++--- 7 files changed, 68 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index e0d5b1c..ece0e12 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This project is not in a finished state, but the core functionality is present. ## License -TagRSS is copyright (c) 2023-present Arjun Satarkar \. +TagRSS is copyright © 2023-present Arjun Satarkar \. TagRSS is licensed under the GNU Affero General Public License v3.0, which requires among other things that "\[w\]hen a modified version is used to provide a service over a network, the complete source code of the modified version must be made available."[^1] diff --git a/serve.py b/serve.py index 6f9dea3..3f2b722 100755 --- a/serve.py +++ b/serve.py @@ -163,26 +163,26 @@ def add_feed_view(): def add_feed_effect(): feed_source: str = bottle.request.forms.get("feed_source") # type: ignore tags = parse_space_separated_tags(bottle.request.forms.get("tags")) # type: ignore + custom_title: str = bottle.request.forms.get("title") # type: ignore if len(tags) > MAX_TAGS: raise bottle.HTTPError(400, f"A feed cannot have more than {MAX_TAGS} tags.") - already_present: bool = False - try: feed_id = core.add_feed( source=feed_source, tags=tags, + custom_title=custom_title if custom_title else None, ) logging.info(f"Added feed {feed_id} (source: {feed_source}).") except tagrss.FeedSourceAlreadyExistsError: - already_present = True + raise bottle.HTTPError( + 400, f"Cannot add feed from {feed_source} as it was already added." + ) except tagrss.FeedTitleAlreadyInUseError as e: - # TODO: add option to set title on /add_feed so this can be remedied without - # changing the existing feed raise bottle.HTTPError( 400, - f"Cannot add feed with title {str(e)} as another feed already has that " + f'Cannot add feed with title "{str(e)}" as another feed already has that ' "title.", ) # TODO: handle FeedFetchError too @@ -190,7 +190,6 @@ def add_feed_effect(): "add_feed", after_add=True, feed_source=feed_source, - already_present=already_present, ) diff --git a/static/styles/main.css b/static/styles/main.css index c7fdf59..f6c6a27 100644 --- a/static/styles/main.css +++ b/static/styles/main.css @@ -21,10 +21,11 @@ body { } a:visited { - color:violet; + color: violet; } -a:link, a.no-visited-indication { +a:link, +a.no-visited-indication { color: lightskyblue; } @@ -34,7 +35,8 @@ table { border: 1px solid white; } -th, td { +th, +td { border: 1px solid white; } @@ -49,18 +51,36 @@ span.tag { padding-left: 0.2em; } -@media (pointer: coarse), (hover: none) { +@media (pointer: coarse), +(hover: none) { div.side-by-side-help-container { display: table-row; } - div.side-by-side-help-container > * { + div.side-by-side-help-container>* { display: table-cell; } - div.side-by-side-help-container > .hover-help:focus::after { + div.side-by-side-help-container>.hover-help:focus::after { content: attr(title); font-size: small; padding-left: 0.2em; } } + +form { + display: table; +} + +form>div { + display: table-row; +} + +form>div>label { + padding-right: 1em; +} + +form>div>label, +form>div>input { + display: table-cell; +} \ No newline at end of file diff --git a/tagrss.py b/tagrss.py index a57d880..8c9ec81 100644 --- a/tagrss.py +++ b/tagrss.py @@ -276,7 +276,11 @@ class SqliteStorageProvider(StorageProvider): conn.execute("DELETE FROM feeds WHERE id = ?;", (feed_id,)) def store_entries( - self, *, parsed: ParsedFeed, feed_id: FeedId, epoch_downloaded: Epoch + self, + *, + parsed: ParsedFeed, + feed_id: FeedId, + epoch_downloaded: Epoch, ) -> None: for entry in reversed(parsed.entries): link: typing.Optional[str] = entry.get("link", None) # type: ignore @@ -408,15 +412,19 @@ class TagRss: return (parsed, epoch_downloaded) def add_feed( - self, - source: str, - tags: list[str], + self, source: str, tags: list[str], custom_title: typing.Optional[str] = None ) -> int: parsed, epoch_downloaded = self.__fetch_and_parse_feed(source) title: str = parsed.feed.get("title", "") # type: ignore - feed_id = self.__storage.store_feed(source=source, title=title, tags=tags) + feed_id = self.__storage.store_feed( + source=source, + title=custom_title if custom_title else title, + tags=tags, + ) self.__storage.store_entries( - parsed=parsed, feed_id=feed_id, epoch_downloaded=epoch_downloaded + parsed=parsed, + feed_id=feed_id, + epoch_downloaded=epoch_downloaded, ) return feed_id diff --git a/views/add_feed.tpl b/views/add_feed.tpl index 4b139d3..04a1008 100644 --- a/views/add_feed.tpl +++ b/views/add_feed.tpl @@ -8,20 +8,20 @@ < home - % if not get("already_present", False): - % if get("after_add", False): -

Added feed {{feed_source}}

- % end - % else: -

Feed {{feed_source}} was already added; no changes made.

+ % if get("after_add", False): +

Added feed {{feed_source}}

% end

Add a feed

- -
+
+ + +
% include("tag_input.tpl", input_name="tags") +
+ + +
% include("footer.tpl") diff --git a/views/manage_feed.tpl b/views/manage_feed.tpl index dce9dc5..a26c6bc 100644 --- a/views/manage_feed.tpl +++ b/views/manage_feed.tpl @@ -35,13 +35,15 @@
- - - + +
+ + +
+
+ + +
% include("tag_input.tpl", input_name="tags", input_value=feed["serialised_tags"])
diff --git a/views/tag_input.tpl b/views/tag_input.tpl index 99145e9..409360f 100644 --- a/views/tag_input.tpl +++ b/views/tag_input.tpl @@ -1,6 +1,5 @@
- + + % include("hover_help.tpl", text="Space-separated. Backslashes escape spaces.")
-- cgit v1.2.3-57-g22cb