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
+31
-1
@@ -1,6 +1,6 @@
|
||||
from django import forms
|
||||
|
||||
from .models import Folder
|
||||
from .models import Folder, Subscription
|
||||
|
||||
|
||||
class AddFeedForm(forms.Form):
|
||||
@@ -13,5 +13,35 @@ class AddFeedForm(forms.Form):
|
||||
self.fields["folder"].queryset = Folder.objects.filter(user=user)
|
||||
|
||||
|
||||
class EditSubscriptionForm(forms.ModelForm):
|
||||
new_folder_name = forms.CharField(
|
||||
label="Or create a new folder",
|
||||
max_length=255,
|
||||
required=False,
|
||||
help_text="Leave blank to use the folder selected above.",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Subscription
|
||||
fields = ["custom_title", "folder"]
|
||||
labels = {"custom_title": "Title (leave blank to use the feed's own title)"}
|
||||
|
||||
def __init__(self, *args, user=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._user = user
|
||||
self.fields["folder"].queryset = Folder.objects.filter(user=user)
|
||||
self.fields["folder"].required = False
|
||||
|
||||
def save(self, commit=True):
|
||||
subscription = super().save(commit=False)
|
||||
new_folder_name = self.cleaned_data.get("new_folder_name", "").strip()
|
||||
if new_folder_name:
|
||||
folder, _created = Folder.objects.get_or_create(user=self._user, name=new_folder_name)
|
||||
subscription.folder = folder
|
||||
if commit:
|
||||
subscription.save()
|
||||
return subscription
|
||||
|
||||
|
||||
class OPMLImportForm(forms.Form):
|
||||
opml_file = forms.FileField(label="OPML file")
|
||||
@@ -3,7 +3,7 @@ from django.contrib.auth import get_user_model
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.urls import reverse
|
||||
|
||||
from .models import Feed, Subscription
|
||||
from .models import Feed, Folder, Subscription
|
||||
from .test_opml import SIMPLE_OPML
|
||||
|
||||
User = get_user_model()
|
||||
@@ -38,6 +38,107 @@ def test_subscription_list_shows_only_own_subscriptions(client, alice, bob, alic
|
||||
assert "Example" not in response.content.decode()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_edit_subscription_updates_title_and_folder(client, alice, alices_subscription):
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
folder = Folder.objects.create(user=alice, name="Tech")
|
||||
|
||||
response = client.post(
|
||||
reverse("feeds:edit_subscription", args=[alices_subscription.pk]),
|
||||
{"custom_title": "My Example Feed", "folder": folder.pk},
|
||||
)
|
||||
|
||||
assert response.status_code == 302
|
||||
alices_subscription.refresh_from_db()
|
||||
assert alices_subscription.custom_title == "My Example Feed"
|
||||
assert alices_subscription.folder == folder
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_edit_subscription_can_create_a_new_folder(client, alice, alices_subscription):
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
|
||||
response = client.post(
|
||||
reverse("feeds:edit_subscription", args=[alices_subscription.pk]),
|
||||
{"custom_title": "", "folder": "", "new_folder_name": "Brand New Folder"},
|
||||
)
|
||||
|
||||
assert response.status_code == 302
|
||||
alices_subscription.refresh_from_db()
|
||||
assert alices_subscription.folder.name == "Brand New Folder"
|
||||
assert Folder.objects.filter(user=alice, name="Brand New Folder").count() == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_edit_subscription_can_clear_folder(client, alice, alices_subscription):
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
alices_subscription.folder = Folder.objects.create(user=alice, name="Tech")
|
||||
alices_subscription.save()
|
||||
|
||||
response = client.post(
|
||||
reverse("feeds:edit_subscription", args=[alices_subscription.pk]),
|
||||
{"custom_title": "", "folder": ""},
|
||||
)
|
||||
|
||||
assert response.status_code == 302
|
||||
alices_subscription.refresh_from_db()
|
||||
assert alices_subscription.folder is None
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_user_cannot_edit_another_users_subscription(client, alice, bob, alices_subscription):
|
||||
client.login(username="bob", password="pw-bob-123")
|
||||
response = client.get(reverse("feeds:edit_subscription", args=[alices_subscription.pk]))
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_add_tag_to_subscription_creates_tag_and_link(client, alice, alices_subscription):
|
||||
from apps.articles.models import SubscriptionTag, Tag
|
||||
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
|
||||
response = client.post(
|
||||
reverse("feeds:add_tag_to_subscription", args=[alices_subscription.pk]),
|
||||
{"tag_name": "backend"},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
tag = Tag.objects.get(user=alice, name="backend")
|
||||
assert SubscriptionTag.objects.filter(
|
||||
user=alice, subscription=alices_subscription, tag=tag
|
||||
).exists()
|
||||
assert b"backend" in response.content
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_remove_tag_from_subscription(client, alice, alices_subscription):
|
||||
from apps.articles.models import SubscriptionTag, Tag
|
||||
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
tag = Tag.objects.create(user=alice, name="backend")
|
||||
SubscriptionTag.objects.create(user=alice, subscription=alices_subscription, tag=tag)
|
||||
|
||||
response = client.post(
|
||||
reverse("feeds:remove_tag_from_subscription", args=[alices_subscription.pk, tag.pk])
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert not SubscriptionTag.objects.filter(
|
||||
user=alice, subscription=alices_subscription, tag=tag
|
||||
).exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_user_cannot_tag_another_users_subscription(client, alice, bob, alices_subscription):
|
||||
client.login(username="bob", password="pw-bob-123")
|
||||
response = client.post(
|
||||
reverse("feeds:add_tag_to_subscription", args=[alices_subscription.pk]),
|
||||
{"tag_name": "backend"},
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_unsubscribe(client, alice, alices_subscription):
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
|
||||
@@ -7,6 +7,26 @@ app_name = "feeds"
|
||||
urlpatterns = [
|
||||
path("feeds/add/", views.add_feed, name="add_feed"),
|
||||
path("subscriptions/", views.subscription_list, name="subscription_list"),
|
||||
path(
|
||||
"subscriptions/<int:subscription_id>/edit/",
|
||||
views.edit_subscription,
|
||||
name="edit_subscription",
|
||||
),
|
||||
path(
|
||||
"subscriptions/<int:subscription_id>/tags/",
|
||||
views.subscription_tags_partial,
|
||||
name="subscription_tags_partial",
|
||||
),
|
||||
path(
|
||||
"subscriptions/<int:subscription_id>/tags/add/",
|
||||
views.add_tag_to_subscription,
|
||||
name="add_tag_to_subscription",
|
||||
),
|
||||
path(
|
||||
"subscriptions/<int:subscription_id>/tags/<int:tag_id>/remove/",
|
||||
views.remove_tag_from_subscription,
|
||||
name="remove_tag_from_subscription",
|
||||
),
|
||||
path(
|
||||
"subscriptions/<int:subscription_id>/unsubscribe/",
|
||||
views.unsubscribe,
|
||||
|
||||
+57
-1
@@ -6,7 +6,10 @@ from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from .forms import AddFeedForm, OPMLImportForm
|
||||
from apps.articles.forms import AddTagForm
|
||||
from apps.articles.models import SubscriptionTag, Tag
|
||||
|
||||
from .forms import AddFeedForm, EditSubscriptionForm, OPMLImportForm
|
||||
from .models import Feed, Subscription
|
||||
from .opml import export_opml, import_opml, parse_opml
|
||||
from .services.fetcher import fetch_and_ingest
|
||||
@@ -63,6 +66,59 @@ def subscription_list(request):
|
||||
return render(request, "feeds/subscriptions.html", {"subscriptions": subscriptions})
|
||||
|
||||
|
||||
@login_required
|
||||
def edit_subscription(request, subscription_id):
|
||||
subscription = get_object_or_404(Subscription, user=request.user, pk=subscription_id)
|
||||
form = EditSubscriptionForm(request.POST or None, instance=subscription, user=request.user)
|
||||
if request.method == "POST" and form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, f"Updated '{subscription.display_title}'.")
|
||||
return redirect("feeds:subscription_list")
|
||||
|
||||
return render(
|
||||
request, "feeds/edit_subscription.html", {"form": form, "subscription": subscription}
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def subscription_tags_partial(request, subscription_id):
|
||||
subscription = get_object_or_404(Subscription, user=request.user, pk=subscription_id)
|
||||
tags = Tag.objects.filter(
|
||||
subscription_tags__subscription=subscription, subscription_tags__user=request.user
|
||||
)
|
||||
all_user_tags = Tag.objects.filter(user=request.user).exclude(pk__in=[t.pk for t in tags])
|
||||
return render(
|
||||
request,
|
||||
"feeds/_subscription_tags.html",
|
||||
{"subscription": subscription, "tags": tags, "all_user_tags": all_user_tags},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def add_tag_to_subscription(request, subscription_id):
|
||||
subscription = get_object_or_404(Subscription, user=request.user, pk=subscription_id)
|
||||
form = AddTagForm(request.POST)
|
||||
if form.is_valid():
|
||||
tag_name = form.cleaned_data["tag_name"].strip()
|
||||
if tag_name:
|
||||
tag, _ = Tag.objects.get_or_create(user=request.user, name=tag_name)
|
||||
SubscriptionTag.objects.get_or_create(
|
||||
user=request.user, subscription=subscription, tag=tag
|
||||
)
|
||||
return subscription_tags_partial(request, subscription_id)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def remove_tag_from_subscription(request, subscription_id, tag_id):
|
||||
subscription = get_object_or_404(Subscription, user=request.user, pk=subscription_id)
|
||||
SubscriptionTag.objects.filter(
|
||||
user=request.user, subscription=subscription, tag_id=tag_id
|
||||
).delete()
|
||||
return subscription_tags_partial(request, subscription_id)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def unsubscribe(request, subscription_id):
|
||||
|
||||
Reference in new issue
Block a user