Private
Public Access
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c6227af57 | ||
|
|
c339d456e4 | ||
|
|
7afda7d0ba |
No files matched your search
+68
-3
@@ -204,7 +204,7 @@ def test_article_rows_carry_their_utc_instant_for_client_side_date_grouping(clie
|
||||
dated = Article.objects.create(
|
||||
feed=feed, guid="dated", title="Dated", published_at=timezone.now()
|
||||
)
|
||||
undated = Article.objects.create(feed=feed, guid="undated", title="Undated")
|
||||
undated = Article.objects.create(feed=feed, guid="undated", title="No publish date")
|
||||
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
response = client.get(reverse("reader:stream"), {"filter": "all"})
|
||||
@@ -214,9 +214,15 @@ def test_article_rows_carry_their_utc_instant_for_client_side_date_grouping(clie
|
||||
assert f'id="article-{dated.pk}"' in content
|
||||
assert f'data-published-utc="{expected_iso}"' in content
|
||||
|
||||
undated_row = re.search(rf'<li id="article-{undated.pk}".*?>', content, flags=re.DOTALL)
|
||||
# A feed that gave no publish date falls back to when it was fetched
|
||||
# (the same fallback the stream's sort order uses), so the row still
|
||||
# carries a time and groups under a real date, not "Undated".
|
||||
undated_row = re.search(rf'<li id="article-{undated.pk}".*?</li>', content, flags=re.DOTALL)
|
||||
assert undated_row is not None
|
||||
assert 'data-published-utc=""' in undated_row.group(0)
|
||||
row_html = undated_row.group(0)
|
||||
assert f'data-published-utc="{undated.fetched_at.isoformat()}"' in row_html
|
||||
assert 'class="article-time"' in row_html
|
||||
assert "Undated" not in content
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@@ -438,3 +444,62 @@ def test_stream_pagination_links_keep_the_feed_scope(client, alice):
|
||||
_, content = _stream_article_ids(client, {"filter": "all", "feed": feed.pk})
|
||||
|
||||
assert _link_query(content, "Older")["feed"] == str(feed.pk)
|
||||
|
||||
|
||||
def test_templates_use_no_inline_event_handlers():
|
||||
"""Production's CSP (script-src 'self') blocks inline on*= handlers —
|
||||
they work in dev, where no CSP is sent, and silently do nothing in
|
||||
production. Behavior belongs in static/js."""
|
||||
from pathlib import Path
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
pattern = re.compile(r"""<[^>]+\s(on[a-z]+)\s*=""", re.IGNORECASE)
|
||||
offenders = []
|
||||
for template in Path(settings.BASE_DIR, "templates").rglob("*.html"):
|
||||
for match in pattern.finditer(template.read_text()):
|
||||
offenders.append(f"{template.name}: {match.group(1)}")
|
||||
assert offenders == []
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_article_detail_back_link_keeps_the_stream_scope(client, alice):
|
||||
feed = Feed.objects.create(feed_url="https://example.com/feed.xml")
|
||||
Subscription.objects.create(user=alice, feed=feed)
|
||||
article = Article.objects.create(feed=feed, guid="g1", title="Hello")
|
||||
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
stream = client.get(
|
||||
reverse("reader:stream"), {"filter": "all", "feed": feed.pk}
|
||||
).content.decode()
|
||||
link = re.search(r'href="(/articles/\d+/\?[^"]+)"', stream)
|
||||
assert link is not None
|
||||
|
||||
detail = client.get(link.group(1).replace("&", "&")).content.decode()
|
||||
assert f"filter=all&feed={feed.pk}" in detail
|
||||
assert "Back to stream" in detail
|
||||
assert article.title in detail
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_article_with_no_publish_date_shows_when_it_was_fetched(client, alice):
|
||||
"""A feed that gives no date is treated as published when we fetched
|
||||
it — in the list row, its group header, and the open article's header
|
||||
— without storing an invented value on the article itself."""
|
||||
feed = Feed.objects.create(feed_url="https://example.com/feed.xml")
|
||||
Subscription.objects.create(user=alice, feed=feed)
|
||||
article = Article.objects.create(feed=feed, guid="g1", title="No publish date")
|
||||
assert article.published_at is None
|
||||
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
iso = article.fetched_at.isoformat()
|
||||
|
||||
stream = client.get(reverse("reader:stream"), {"filter": "all"}).content.decode()
|
||||
assert f'datetime="{iso}"' in stream
|
||||
assert "Received today" in stream
|
||||
|
||||
detail = client.get(reverse("reader:article_detail", args=[article.pk])).content.decode()
|
||||
assert f'datetime="{iso}"' in detail
|
||||
|
||||
article.refresh_from_db()
|
||||
assert article.published_at is None
|
||||
+11
-2
@@ -113,7 +113,8 @@ def _group_by_date(articles):
|
||||
today = timezone.localdate()
|
||||
|
||||
def day_of(article):
|
||||
return timezone.localtime(article.published_at).date() if article.published_at else None
|
||||
when = article.published_at or article.fetched_at
|
||||
return timezone.localtime(when).date() if when else None
|
||||
|
||||
return [
|
||||
{"label": _date_label(day, today), "articles": list(items)}
|
||||
@@ -238,6 +239,7 @@ def stream(request):
|
||||
# regardless of how a feed backdates an entry's published date.
|
||||
"latest_article_id": queryset.aggregate(Max("id"))["id__max"] or 0,
|
||||
"new_check_qs": urlencode(scope_params),
|
||||
"scope_qs": urlencode(scope_params),
|
||||
}
|
||||
return render(request, "reader/stream.html", context)
|
||||
|
||||
@@ -311,7 +313,14 @@ def _load_article_and_mark_read(user, article_id):
|
||||
@login_required
|
||||
def article_detail(request, article_id):
|
||||
article = _load_article_and_mark_read(request.user, article_id)
|
||||
return render(request, "reader/article_detail.html", {"article": article})
|
||||
# The stream passes its filter/tag/feed scope through the link so
|
||||
# "Back to stream" returns to it instead of resetting to every feed.
|
||||
back_params = {k: request.GET[k] for k in ("filter", "tag", "feed") if request.GET.get(k)}
|
||||
return render(
|
||||
request,
|
||||
"reader/article_detail.html",
|
||||
{"article": article, "back_qs": urlencode(back_params)},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
|
||||
@@ -559,6 +559,7 @@ form p {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-dim);
|
||||
flex: 0 0 auto;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.article-actions {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// instant plus a UTC-formatted fallback as their initial text, and this
|
||||
// reformats them using the browser's own timezone, client-side, so the
|
||||
// server never needs to know (or guess) where the viewer actually is.
|
||||
var SHORT_OPTIONS = { hour: "numeric", minute: "2-digit" };
|
||||
var SHORT_OPTIONS = { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" };
|
||||
var LONG_OPTIONS = {
|
||||
year: "numeric",
|
||||
month: "short",
|
||||
@@ -21,6 +21,10 @@
|
||||
var date = new Date(iso);
|
||||
if (isNaN(date.getTime())) return;
|
||||
var options = el.dataset.localFormat === "short" ? SHORT_OPTIONS : LONG_OPTIONS;
|
||||
if (options === SHORT_OPTIONS && date.getFullYear() !== new Date().getFullYear()) {
|
||||
// Date-only rows from a previous year would otherwise be ambiguous.
|
||||
options = Object.assign({ year: "numeric" }, SHORT_OPTIONS);
|
||||
}
|
||||
try {
|
||||
el.textContent = date.toLocaleString(undefined, options);
|
||||
} catch (e) {
|
||||
|
||||
+23
-5
@@ -1,8 +1,11 @@
|
||||
function toggleArticle(event, id) {
|
||||
event.preventDefault();
|
||||
var link = event.currentTarget;
|
||||
// Delegated listeners, not inline onclick="" attributes: production's
|
||||
// Content Security Policy (config/settings/prod.py, script-src 'self')
|
||||
// blocks inline event handlers, which silently turned the title click into
|
||||
// a plain link to the detail page and the new-articles banner into a no-op.
|
||||
|
||||
function toggleArticle(link) {
|
||||
var row = link.closest("li.article-row");
|
||||
var body = document.getElementById("article-body-" + id);
|
||||
var body = row.querySelector(".article-inline-body");
|
||||
var wasOpen = row.classList.contains("is-expanded");
|
||||
|
||||
document.querySelectorAll("li.article-row.is-expanded").forEach(function (openRow) {
|
||||
@@ -25,5 +28,20 @@ function toggleArticle(event, id) {
|
||||
);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var link = event.target.closest("a.article-title[data-inline-url]");
|
||||
if (link) {
|
||||
// Leave modified clicks alone so "open in new tab" still works.
|
||||
if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
toggleArticle(link);
|
||||
return;
|
||||
}
|
||||
if (event.target.closest(".new-articles-banner")) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
@@ -3,9 +3,8 @@
|
||||
<p class="article-meta">
|
||||
{% if article.feed.favicon_url %}<img src="{{ article.feed.favicon_url }}" alt="" class="feed-favicon">{% endif %}
|
||||
{{ article.feed.title }}
|
||||
{% if article.published_at %}
|
||||
· <time datetime="{{ article.published_at|date:"c" }}" data-local-format="long">{{ article.published_at|date:"M j, Y H:i" }}</time>
|
||||
{% endif %}
|
||||
{# fetched_at stands in when the feed gave no publish date #}
|
||||
· <time datetime="{{ article.published_at|default:article.fetched_at|date:"c" }}" data-local-format="long">{{ article.published_at|default:article.fetched_at|date:"M j, Y H:i" }}</time>
|
||||
{% if article.author %} · {{ article.author }}{% endif %}
|
||||
{% if article.link %} · <a href="{{ article.link }}" target="_blank" rel="noopener noreferrer">Original ↗</a>{% endif %}
|
||||
</p>
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
<li id="article-{{ article.pk }}" class="article-row{% if article.is_read %} is-read{% endif %}"
|
||||
data-published-utc="{% if article.published_at %}{{ article.published_at|date:"c" }}{% endif %}">
|
||||
data-published-utc="{{ article.published_at|default:article.fetched_at|date:"c" }}">
|
||||
<div class="article-row-main">
|
||||
{% include "reader/_article_actions.html" %}
|
||||
{% if article.feed.favicon_url %}
|
||||
<img src="{{ article.feed.favicon_url }}" alt="" class="feed-favicon">
|
||||
{% endif %}
|
||||
<span class="article-feed-name">{{ article.feed.title|default:article.feed.feed_url }}</span>
|
||||
<a href="{% url 'reader:article_detail' article.pk %}" class="article-title"
|
||||
data-inline-url="{% url 'reader:article_inline' article.pk %}"
|
||||
onclick="return toggleArticle(event, {{ article.pk }})">{{ article.title|default:"(untitled)" }}</a>
|
||||
{% if article.published_at %}
|
||||
<time class="article-time" datetime="{{ article.published_at|date:"c" }}" data-local-format="short">{{ article.published_at|date:"g:i A" }}</time>
|
||||
{% endif %}
|
||||
<a href="{% url 'reader:article_detail' article.pk %}{% if scope_qs %}?{{ scope_qs }}{% endif %}" class="article-title"
|
||||
data-inline-url="{% url 'reader:article_inline' article.pk %}">{{ article.title|default:"(untitled)" }}</a>
|
||||
{# fetched_at stands in when a feed gives no publish date — same fallback the stream's sort order uses #}
|
||||
<time class="article-time" datetime="{{ article.published_at|default:article.fetched_at|date:"c" }}" data-local-format="short">{{ article.published_at|default:article.fetched_at|date:"M j, g:i A" }}</time>
|
||||
</div>
|
||||
<div id="article-body-{{ article.pk }}" class="article-inline-body" hidden></div>
|
||||
</li>
|
||||
@@ -1,5 +1,5 @@
|
||||
{% if new_count %}
|
||||
<button type="button" class="new-articles-banner" onclick="location.reload()">
|
||||
<button type="button" class="new-articles-banner">
|
||||
{{ new_count }} new article{{ new_count|pluralize }} — click to show
|
||||
</button>
|
||||
{% endif %}
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{{ article.title|default:"Article" }} — Evection{% endblock %}
|
||||
{% block content %}
|
||||
<p><a href="{% url 'reader:stream' %}">← Back to stream</a></p>
|
||||
<p><a href="{% url 'reader:stream' %}{% if back_qs %}?{{ back_qs }}{% endif %}">← Back to stream</a></p>
|
||||
<article>
|
||||
{% include "reader/_article_actions.html" %}
|
||||
{% include "reader/_article_content.html" %}
|
||||
|
||||
Reference in new issue
Block a user