Private
Public Access
Add subscription editing, feed-level tags, and a remembered stream filter
Subscription editing was a real gap: there was no way to rename a feed's display title, move it between folders, or create a folder at all outside OPML import. Added an edit page (apps/feeds/views.py:edit_subscription, EditSubscriptionForm) reachable from the subscriptions list. Added feed-level tagging via a new SubscriptionTag model (apps/articles/ models.py), mirroring the existing ArticleTag — tag a whole feed on its edit page, and every one of its articles surfaces under that tag in the stream alongside individually-tagged articles (apps.reader.views._apply_ scope now matches either). Renamed AddTagToArticleForm to AddTagForm since it's shared by both now. The stream also now remembers the last filter (unread/all/starred/saved) in the session instead of always defaulting to "unread" when a sidebar feed/folder/tag link omits ?filter= — sidebar links no longer force ?filter=all, letting the remembered choice apply. Verified end to end against a running dev server: editing a subscription's title/folder, creating a folder inline, tagging a feed and seeing its articles appear under that tag, and the remembered-filter behavior across requests with no ?filter= param. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cfa64b5485
commit
3b58fdcb7e
15 files changed
+376
-23
No files matched your search
@@ -116,6 +116,34 @@ def test_user_cannot_toggle_state_on_another_users_article(client, alice, bob, a
|
||||
assert not UserArticleState.objects.filter(article=alices_article).exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_stream_remembers_last_selected_filter(client, alice, alices_article):
|
||||
UserArticleState.objects.create(user=alice, article=alices_article, is_starred=True)
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
|
||||
response = client.get(reverse("reader:stream"), {"filter": "starred"})
|
||||
assert response.context["active_filter"] == "starred"
|
||||
|
||||
# No ?filter= this time — e.g. a sidebar feed/tag link, or just "/" —
|
||||
# should fall back to "starred" rather than resetting to "unread".
|
||||
response = client.get(reverse("reader:stream"))
|
||||
assert response.context["active_filter"] == "starred"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_tag_filter_includes_articles_from_a_tagged_feed(client, alice, alices_article):
|
||||
from apps.articles.models import SubscriptionTag, Tag
|
||||
from apps.feeds.models import Subscription
|
||||
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
tag = Tag.objects.create(user=alice, name="backend")
|
||||
subscription = Subscription.objects.get(user=alice, feed=alices_article.feed)
|
||||
SubscriptionTag.objects.create(user=alice, subscription=subscription, tag=tag)
|
||||
|
||||
response = client.get(reverse("reader:stream"), {"filter": "all", "tag": tag.pk})
|
||||
assert alices_article.title in response.content.decode()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_saved_filter_only_shows_saved_articles(client, alice, alices_article):
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
|
||||
+21
-5
@@ -1,6 +1,7 @@
|
||||
from itertools import groupby
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Q
|
||||
from django.http import Http404
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse
|
||||
@@ -50,9 +51,18 @@ def _apply_scope(request, queryset):
|
||||
if tag_id:
|
||||
active_tag = Tag.objects.filter(user=request.user, pk=tag_id).first()
|
||||
if active_tag:
|
||||
# A tag matches an article either directly (ArticleTag) or by
|
||||
# the article's feed being tagged via the user's Subscription
|
||||
# (SubscriptionTag) — tagging a whole feed surfaces all of its
|
||||
# articles under that tag, not just individually-tagged ones.
|
||||
queryset = queryset.filter(
|
||||
article_tags__user=request.user, article_tags__tag=active_tag
|
||||
)
|
||||
Q(article_tags__user=request.user, article_tags__tag=active_tag)
|
||||
| Q(
|
||||
feed__subscriptions__user=request.user,
|
||||
feed__subscriptions__subscription_tags__user=request.user,
|
||||
feed__subscriptions__subscription_tags__tag=active_tag,
|
||||
)
|
||||
).distinct()
|
||||
|
||||
active_feed = None
|
||||
feed_id = request.GET.get("feed")
|
||||
@@ -101,9 +111,15 @@ def _group_by_date(articles):
|
||||
|
||||
@login_required
|
||||
def stream(request):
|
||||
active_filter = request.GET.get("filter", "unread")
|
||||
if active_filter not in VALID_FILTERS:
|
||||
active_filter = "unread"
|
||||
requested_filter = request.GET.get("filter")
|
||||
if requested_filter in VALID_FILTERS:
|
||||
active_filter = requested_filter
|
||||
else:
|
||||
# No (valid) filter in the URL — e.g. a sidebar feed/folder/tag
|
||||
# link, or just "/" — falls back to whatever the user last had
|
||||
# selected, rather than always resetting to "unread".
|
||||
active_filter = request.session.get("stream_filter", "unread")
|
||||
request.session["stream_filter"] = active_filter
|
||||
|
||||
queryset = _base_queryset(request.user)
|
||||
if active_filter == "unread":
|
||||
|
||||
Reference in new issue
Block a user