Private
Public Access
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd68400822 | ||
|
|
90837b339c |
No files matched your search
+15
-5
@@ -1,18 +1,28 @@
|
||||
from django.contrib import admin
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
|
||||
from .models import SiteSettings
|
||||
|
||||
|
||||
@admin.register(SiteSettings)
|
||||
class SiteSettingsAdmin(admin.ModelAdmin):
|
||||
list_display = ["fetch_interval_minutes"]
|
||||
"""A true singleton, not a collection — browsing a changelist to pick
|
||||
the one row and click into it is an extra, pointless step, so
|
||||
"Core > Site settings" in the sidebar goes straight to the (only)
|
||||
change form instead, creating the row first if this is a fresh
|
||||
install. No changelist/add/delete views exist at all here.
|
||||
"""
|
||||
|
||||
fields = ["fetch_interval_minutes"]
|
||||
|
||||
def has_add_permission(self, request):
|
||||
# Singleton — only offer "Add" when the row doesn't exist yet
|
||||
# (a fresh install before the first poll_due_feeds run or admin
|
||||
# visit has created it via SiteSettings.load()).
|
||||
return not SiteSettings.objects.exists()
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def changelist_view(self, request, extra_context=None):
|
||||
settings_row = SiteSettings.load()
|
||||
url = reverse("admin:core_sitesettings_change", args=[settings_row.pk])
|
||||
return redirect(url)
|
||||
@@ -51,7 +51,21 @@ def test_poll_due_feeds_uses_the_site_wide_interval_for_every_feed():
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_admin_offers_add_only_once_and_never_offers_delete(client):
|
||||
def test_admin_changelist_redirects_straight_to_the_change_form(client):
|
||||
assert not SiteSettings.objects.exists()
|
||||
User.objects.create_superuser("admin", password="pw-admin-123")
|
||||
client.login(username="admin", password="pw-admin-123")
|
||||
|
||||
changelist_url = reverse("admin:core_sitesettings_changelist")
|
||||
response = client.get(changelist_url)
|
||||
|
||||
settings_row = SiteSettings.objects.get() # created by the redirect itself
|
||||
assert response.status_code == 302
|
||||
assert response.url == reverse("admin:core_sitesettings_change", args=[settings_row.pk])
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_admin_never_offers_add_or_delete(client):
|
||||
# ModelAdmin.has_add_permission/has_delete_permission returning False
|
||||
# makes Django raise PermissionDenied rather than build a 403 response
|
||||
# directly — the test client's default behavior re-raises that for
|
||||
@@ -61,14 +75,10 @@ def test_admin_offers_add_only_once_and_never_offers_delete(client):
|
||||
User.objects.create_superuser("admin", password="pw-admin-123")
|
||||
client.login(username="admin", password="pw-admin-123")
|
||||
|
||||
add_url = reverse("admin:core_sitesettings_add")
|
||||
response = client.get(add_url)
|
||||
assert response.status_code == 200 # no row yet — "Add" is offered
|
||||
response = client.get(reverse("admin:core_sitesettings_add"))
|
||||
assert response.status_code == 403
|
||||
|
||||
settings_row = SiteSettings.load()
|
||||
response = client.get(add_url)
|
||||
assert response.status_code == 403 # a row exists now — add is refused
|
||||
|
||||
delete_url = reverse("admin:core_sitesettings_delete", args=[settings_row.pk])
|
||||
response = client.get(delete_url)
|
||||
assert response.status_code == 403
|
||||
@@ -0,0 +1,41 @@
|
||||
(function () {
|
||||
// Everything is stored and server-rendered in UTC (config.settings.base
|
||||
// TIME_ZONE) — these <time datetime="..."> elements carry that UTC
|
||||
// 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 LONG_OPTIONS = {
|
||||
year: "numeric",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
};
|
||||
|
||||
function localizeTimesWithin(root) {
|
||||
if (!root || typeof root.querySelectorAll !== "function") return;
|
||||
root.querySelectorAll("time[data-local-format]").forEach(function (el) {
|
||||
var iso = el.getAttribute("datetime");
|
||||
if (!iso) return;
|
||||
var date = new Date(iso);
|
||||
if (isNaN(date.getTime())) return;
|
||||
var options = el.dataset.localFormat === "short" ? SHORT_OPTIONS : LONG_OPTIONS;
|
||||
try {
|
||||
el.textContent = date.toLocaleString(undefined, options);
|
||||
} catch (e) {
|
||||
/* Intl unavailable or threw — leave the server-rendered UTC text as-is */
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
localizeTimesWithin(document);
|
||||
|
||||
// Article rows/content are frequently swapped in by htmx (pagination,
|
||||
// the inline expand-article view, the dashboard's retry action) without
|
||||
// a full page load, so every swap needs the same pass over just the
|
||||
// new content.
|
||||
document.body.addEventListener("htmx:afterSwap", function (event) {
|
||||
localizeTimesWithin(event.target);
|
||||
});
|
||||
})();
|
||||
@@ -53,6 +53,7 @@
|
||||
{% endif %}
|
||||
|
||||
<script src="{% static 'js/stream.js' %}" defer></script>
|
||||
<script src="{% static 'js/localize-times.js' %}" defer></script>
|
||||
{% if user.is_authenticated %}
|
||||
<script src="{% static 'js/theme.js' %}" defer></script>
|
||||
<script src="{% static 'js/sidebar-state.js' %}" defer></script>
|
||||
|
||||
@@ -31,7 +31,13 @@
|
||||
<td>{{ feed.subscriber_count }}</td>
|
||||
<td>{{ feed.get_last_fetch_status_display }}</td>
|
||||
<td>{{ feed.fetch_error_count }}</td>
|
||||
<td>{{ feed.last_fetched_at|default:"never" }}</td>
|
||||
<td>
|
||||
{% if feed.last_fetched_at %}
|
||||
<time datetime="{{ feed.last_fetched_at|date:"c" }}" data-local-format="long">{{ feed.last_fetched_at|date:"M j, Y H:i" }}</time>
|
||||
{% else %}
|
||||
never
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ feed.last_error_message|default:"—" }}</td>
|
||||
<td>
|
||||
<form method="post" action="{% url 'core:retry_feed' feed.id %}">
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
<h2 class="article-content-title">{{ article.title|default:"(untitled)" }}</h2>
|
||||
<p class="article-meta">
|
||||
{% if article.feed.favicon_url %}<img src="{{ article.feed.favicon_url }}" alt="" class="feed-favicon">{% endif %}
|
||||
{{ article.feed.title }} · {{ article.published_at|date:"M j, Y H:i" }}
|
||||
{{ 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 %}
|
||||
{% if article.author %} · {{ article.author }}{% endif %}
|
||||
{% if article.link %} · <a href="{{ article.link }}" target="_blank" rel="noopener noreferrer">Original ↗</a>{% endif %}
|
||||
</p>
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
<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>
|
||||
<span class="article-time">{{ article.published_at|date:"g:i A" }}</span>
|
||||
{% 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 %}
|
||||
</div>
|
||||
<div id="article-body-{{ article.pk }}" class="article-inline-body" hidden></div>
|
||||
</li>
|
||||
Reference in new issue
Block a user