aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2023-08-03 21:38:50 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2023-08-03 21:38:50 +0000
commita45bcb74dde80ee576bfcbc2f3efb719e8f6b2d9 (patch)
treea0407eb415e89b8660a8a8d1566230ebf0223e94
parentfc56c91d09da2d9c929be5469fcae73ed2f9d5e3 (diff)
downloadtagrss-a45bcb74dde80ee576bfcbc2f3efb719e8f6b2d9.tar
tagrss-a45bcb74dde80ee576bfcbc2f3efb719e8f6b2d9.tar.gz
tagrss-a45bcb74dde80ee576bfcbc2f3efb719e8f6b2d9.zip
Allow setting custom title on /add_feed, improve form layout
-rw-r--r--README.md2
-rwxr-xr-xserve.py13
-rw-r--r--static/styles/main.css32
-rw-r--r--tagrss.py20
-rw-r--r--views/add_feed.tpl20
-rw-r--r--views/manage_feed.tpl16
-rw-r--r--views/tag_input.tpl5
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 \<me@arjunsatarkar.net\>.
+TagRSS is copyright © 2023-present Arjun Satarkar \<me@arjunsatarkar.net\>.
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 @@
</head>
<body>
<a href="/" class="no-visited-indication">&lt; home</a>
- % if not get("already_present", False):
- % if get("after_add", False):
- <p><em>Added feed {{feed_source}}</em></p>
- % end
- % else:
- <p><em>Feed {{feed_source}} was already added; no changes made.</em></p>
+ % if get("after_add", False):
+ <p><em>Added feed {{feed_source}}</em></p>
% end
<h1>Add a feed</h1>
<form method="post">
- <label>Source:
- <input type="url" name="feed_source">
- </label>
- <br>
+ <div>
+ <label for="feed-source-input">Source:</label>
+ <input type="url" name="feed_source" id="feed-source-input">
+ </div>
% include("tag_input.tpl", input_name="tags")
+ <div>
+ <label for="title-input">Custom title (optional):</label>
+ <input type="text" name="title" id="title-input">
+ </div>
<input type="submit" value="Add">
</form>
% 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 @@
</tr>
</table>
<form method="post">
- <input type="number" name="id" value="{{feed['id']}}" style="display: none;">
- <label>Title:
- <input type="text" name="title" value="{{feed['title']}}"><br>
- </label>
- <label>Source:
- <input type="text" name="source" value="{{feed['source']}}"><br>
- </label>
+ <input type="hidden" name="id" value="{{feed['id']}}">
+ <div>
+ <label for="title-input">Title:</label>
+ <input type="text" name="title" value="{{feed['title']}}" id="title-input">
+ </div>
+ <div>
+ <label for="source-input">Source:</label>
+ <input type="text" name="source" value="{{feed['source']}}" id="source-input">
+ </div>
% include("tag_input.tpl", input_name="tags", input_value=feed["serialised_tags"])
<input type="submit" value="Update" name="update_feed">
</form>
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 @@
<div class="side-by-side-help-container">
- <label>{{get("label", "Tags:")}}
- <input type="text" name="{{input_name}}" value="{{get('input_value', '')}}">
- </label>
+ <label for="tag-input">{{get("label", "Tags:")}}</label>
+ <input type="text" name="{{input_name}}" value="{{get('input_value', '')}}" id="tag-input">
% include("hover_help.tpl", text="Space-separated. Backslashes escape spaces.")
</div>