Properly hide inactive/tts items
This commit is contained in:
parent
ad6da14387
commit
f4b6ef2f1c
|
@ -28,6 +28,15 @@ def item_sort_key(item):
|
||||||
return (item_date, item["id"])
|
return (item_date, item["id"])
|
||||||
|
|
||||||
|
|
||||||
|
def show_item(item):
|
||||||
|
"""
|
||||||
|
Whether to show an item based on active and tts.
|
||||||
|
"""
|
||||||
|
return item["active"] and (
|
||||||
|
"tts" not in item or item["created"] + item["tts"] < int(time.time())
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter("datetimeformat")
|
@app.template_filter("datetimeformat")
|
||||||
def datetimeformat(value):
|
def datetimeformat(value):
|
||||||
if not value:
|
if not value:
|
||||||
|
@ -70,7 +79,9 @@ def source_feed(name):
|
||||||
if not source.source_path.exists():
|
if not source.source_path.exists():
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
return _sources_feed(name, [source])
|
return _sources_feed(
|
||||||
|
name, [source], show_hidden=request.args.get("hidden", True)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/channel/<string:name>")
|
@app.get("/channel/<string:name>")
|
||||||
|
@ -84,18 +95,25 @@ def channel_feed(name):
|
||||||
channels = json.loads(channels_config_path.read_text(encoding="utf8"))
|
channels = json.loads(channels_config_path.read_text(encoding="utf8"))
|
||||||
if name not in channels:
|
if name not in channels:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
sources = [LocalSource(intake_data_dir(), name) for name in channels[name]]
|
sources = [LocalSource(intake_data_dir(), name) for name in channels[name]]
|
||||||
return _sources_feed(name, sources)
|
|
||||||
|
return _sources_feed(
|
||||||
|
name, sources, show_hidden=request.args.get("hidden", False)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _sources_feed(name: str, sources: List[LocalSource]):
|
def _sources_feed(name: str, sources: List[LocalSource], show_hidden: bool):
|
||||||
"""
|
"""
|
||||||
Feed view for multiple sources.
|
Feed view for multiple sources.
|
||||||
"""
|
"""
|
||||||
# Get all items
|
# Get all items
|
||||||
all_items = sorted(
|
all_items = sorted(
|
||||||
[item for source in sources for item in source.get_all_items()],
|
[
|
||||||
|
item
|
||||||
|
for source in sources
|
||||||
|
for item in source.get_all_items()
|
||||||
|
if show_item(item) or show_hidden
|
||||||
|
],
|
||||||
key=item_sort_key,
|
key=item_sort_key,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -106,16 +124,12 @@ def _sources_feed(name: str, sources: List[LocalSource]):
|
||||||
pager_prev = (
|
pager_prev = (
|
||||||
None
|
None
|
||||||
if page <= 0
|
if page <= 0
|
||||||
else url_for(
|
else url_for(request.endpoint, name=name, count=count, page=page - 1)
|
||||||
request.endpoint, name=name, count=count, page=page - 1
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
pager_next = (
|
pager_next = (
|
||||||
None
|
None
|
||||||
if (count * page + count) > len(all_items)
|
if (count * page + count) > len(all_items)
|
||||||
else url_for(
|
else url_for(request.endpoint, name=name, count=count, page=page + 1)
|
||||||
request.endpoint, name=name, count=count, page=page + 1
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
|
|
|
@ -126,7 +126,10 @@ var doAction = function (source, itemid, action) {
|
||||||
</div>
|
</div>
|
||||||
{% if items %}
|
{% if items %}
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
<div class="readable-item {%- if not item.active %} strikethru fade{% endif %}{%- if item.active and item.tts and item.created + item.tts > now %} fade{% endif %}" id="{{item.source}}-{{item.id}}">
|
<div class="readable-item
|
||||||
|
{%- if not item.active %} strikethru fade{% endif %}
|
||||||
|
{%- if item.active and item.tts and item.created + item.tts > now %} fade{% endif -%}
|
||||||
|
" id="{{item.source}}-{{item.id}}">
|
||||||
{% if item.id %}
|
{% if item.id %}
|
||||||
<button class="item-button" onclick="javascript:deactivate('{{item.source}}', '{{item.id}}')" title="Deactivate">✕</button>
|
<button class="item-button" onclick="javascript:deactivate('{{item.source}}', '{{item.id}}')" title="Deactivate">✕</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in New Issue