Skip to content

Commit

Permalink
Web app changes for Entry.important: bool|None.
Browse files Browse the repository at this point in the history
For #254.
  • Loading branch information
lemon24 committed Feb 14, 2023
1 parent 3e6e87a commit 2a383bb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 60 deletions.
27 changes: 10 additions & 17 deletions src/reader/_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions src/reader/_app/templates/entries.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,14 @@ <h2><a href="{{ entry.link }}">{{ title }}</a></h2>
{{ 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' %}
Expand All @@ -306,8 +306,8 @@ <h2><a href="{{ entry.link }}">{{ title }}</a></h2>
('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),
) %}
<li class="error">{{ message }}
Expand Down
14 changes: 7 additions & 7 deletions src/reader/_app/templates/entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -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' %}
Expand All @@ -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),
) %}
<li class="error">{{ message }}
Expand Down
11 changes: 0 additions & 11 deletions src/reader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 0 additions & 18 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down

0 comments on commit 2a383bb

Please sign in to comment.