From 2a383bbb530e8d0a9e59350a4ab8eeb36f363c6b Mon Sep 17 00:00:00 2001 From: lemon24 Date: Wed, 15 Feb 2023 00:33:58 +0200 Subject: [PATCH] Web app changes for Entry.important: bool|None. For #254. --- src/reader/_app/__init__.py | 27 ++++++++++---------------- src/reader/_app/templates/entries.html | 14 ++++++------- src/reader/_app/templates/entry.html | 14 ++++++------- src/reader/core.py | 11 ----------- tests/test_reader.py | 18 ----------------- 5 files changed, 24 insertions(+), 60 deletions(-) diff --git a/src/reader/_app/__init__.py b/src/reader/_app/__init__.py index 959ed675..8a2dd480 100644 --- a/src/reader/_app/__init__.py +++ b/src/reader/_app/__init__.py @@ -593,21 +593,7 @@ def mark_as_read(data): def mark_as_unread(data): feed_url = data['feed-url'] entry_id = data['entry-id'] - id = feed_url, entry_id - reader = get_reader() - reader.mark_entry_as_unread(id) - entry = reader.get_entry(id) - # if we're in "don't care", reset important_modified - if not entry.important and entry.important_modified: - reader.set_entry_important(id, False, modified=None) - - -@form_api -@readererror_to_apierror() -def mark_as_dont_care(data): - feed_url = data['feed-url'] - entry_id = data['entry-id'] - get_reader()._mark_entry_as_dont_care((feed_url, entry_id)) + get_reader().mark_entry_as_unread((feed_url, entry_id)) @form_api(really=True) @@ -636,13 +622,20 @@ def mark_as_important(data): get_reader().mark_entry_as_important((feed_url, entry_id)) +@form_api +@readererror_to_apierror() +def clear_important(data): + feed_url = data['feed-url'] + entry_id = data['entry-id'] + get_reader().set_entry_important((feed_url, entry_id), None) + + @form_api @readererror_to_apierror() def mark_as_unimportant(data): feed_url = data['feed-url'] entry_id = data['entry-id'] - # only "don't care" sets important_modified - get_reader().set_entry_important((feed_url, entry_id), False, modified=None) + get_reader().mark_entry_as_unimportant((feed_url, entry_id)) @form_api(really=True) diff --git a/src/reader/_app/templates/entries.html b/src/reader/_app/templates/entries.html index f0433e3d..76e6ee2b 100644 --- a/src/reader/_app/templates/entries.html +++ b/src/reader/_app/templates/entries.html @@ -281,14 +281,14 @@

{{ title }}

{{ macros.simple_button('.form_api', 'mark-as-read', 'read', leave_disabled=true, next=next, context=context, title=entry.read_modified or "not modified") }} {% endif %} - {% if entry.important %} - {{ macros.simple_button('.form_api', 'mark-as-unimportant', 'unimportant', leave_disabled=true, next=next, context=context, title=entry.important_modified or "not modified") }} - {% else %} + {% if not entry.important %} {{ macros.simple_button('.form_api', 'mark-as-important', 'important', leave_disabled=true, next=next, context=context, title=entry.important_modified or "not modified") }} {% endif %} - - {% if not (entry.read and not entry.important and entry.important_modified) %} - {{ macros.simple_button('.form_api', 'mark-as-dont-care', "don't care", leave_disabled=true, next=next, context=context) }} + {% if entry.important is not none %} + {{ macros.simple_button('.form_api', 'clear-important', "clear " + ("important" if entry.important else "don't care"), leave_disabled=true, next=next, context=context) }} + {% endif %} + {% if entry.important is not false %} + {{ macros.simple_button('.form_api', 'mark-as-unimportant', "don't care", leave_disabled=true, next=next, context=context, title=entry.important_modified or "not modified") }} {% endif %} {% if entry.added_by == 'user' %} @@ -306,8 +306,8 @@

{{ title }}

('mark-as-read', feed.url, entry.id), ('mark-as-unread', feed.url, entry.id), ('mark-as-important', feed.url, entry.id), + ('clear-important', feed.url, entry.id), ('mark-as-unimportant', feed.url, entry.id), - ('mark-as-dont-care', feed.url, entry.id), ('delete-entry', feed.url, entry.id), ) %}
  • {{ message }} diff --git a/src/reader/_app/templates/entry.html b/src/reader/_app/templates/entry.html index e91091eb..7154c463 100644 --- a/src/reader/_app/templates/entry.html +++ b/src/reader/_app/templates/entry.html @@ -33,14 +33,14 @@ {{ macros.simple_button('.form_api', 'mark-as-read', 'read', leave_disabled=true, next=next, context=context, title=entry.read_modified or "not modified") }} {% endif %} -{% if entry.important %} - {{ macros.simple_button('.form_api', 'mark-as-unimportant', 'unimportant', leave_disabled=true, next=next, context=context, title=entry.important_modified or "not modified") }} -{% else %} +{% if not entry.important %} {{ macros.simple_button('.form_api', 'mark-as-important', 'important', leave_disabled=true, next=next, context=context, title=entry.important_modified or "not modified") }} {% endif %} - -{% if not (entry.read and not entry.important and entry.important_modified) %} - {{ macros.simple_button('.form_api', 'mark-as-dont-care', "don't care", leave_disabled=true, next=next, context=context) }} +{% if entry.important is not none %} + {{ macros.simple_button('.form_api', 'clear-important', "clear " + ("important" if entry.important else "don't care"), leave_disabled=true, next=next, context=context) }} +{% endif %} +{% if entry.important is not false %} + {{ macros.simple_button('.form_api', 'mark-as-unimportant', "don't care", leave_disabled=true, next=next, context=context, title=entry.important_modified or "not modified") }} {% endif %} {% if entry.added_by == 'user' %} @@ -57,8 +57,8 @@ ('mark-as-read', feed.url, entry.id), ('mark-as-unread', feed.url, entry.id), ('mark-as-important', feed.url, entry.id), + ('clear-important', feed.url, entry.id), ('mark-as-unimportant', feed.url, entry.id), - ('mark-as-dont-care', feed.url, entry.id), ('delete-entry', feed.url, entry.id), ) %}
  • {{ message }} diff --git a/src/reader/core.py b/src/reader/core.py index f0f7537a..66ac8ad4 100644 --- a/src/reader/core.py +++ b/src/reader/core.py @@ -1471,17 +1471,6 @@ def mark_entry_as_unimportant(self, entry: EntryInput, /) -> None: """ return self.set_entry_important(entry, False) - def _mark_entry_as_dont_care(self, entry: EntryInput, /) -> None: - """Mark an entry as read and unimportant at the same time, - resulting in the same read_modified and important_modified. - - ~This method becoming public is pending on #254.~ - - FIXME: As of Jan 2023, this should be replaced by mark_entry_as_unimportant(). - - """ - self.mark_entry_as_unimportant(entry) - def add_entry(self, entry: Any, /) -> None: """Add a new entry to an existing feed. diff --git a/tests/test_reader.py b/tests/test_reader.py index b4a627af..7ed01c69 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -2862,24 +2862,6 @@ def test_set_entry_important_value_error(reader, value): reader.set_entry_important(entry, value) -@rename_argument('reader', 'reader_with_one_feed') -def test_mark_as_dont_care(reader): - reader.update_feeds() - - entry = next(reader.get_entries()) - reader._now = lambda: naive_datetime(2010, 1, 1) - reader.mark_entry_as_important(entry) - - reader._now = lambda: naive_datetime(2010, 1, 2) - reader._mark_entry_as_dont_care(entry) - entry = next(reader.get_entries()) - - assert not entry.read - assert entry.read_modified is None - assert entry.important is False - assert entry.important_modified == datetime(2010, 1, 2) - - allow_invalid_url_feed_root = 'C:\\tmp' if os.name == 'nt' else '/tmp'