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
@@ -10,9 +10,10 @@ class TagForm(forms.ModelForm):
|
|||||||
widgets = {"color": forms.TextInput(attrs={"type": "color"})}
|
widgets = {"color": forms.TextInput(attrs={"type": "color"})}
|
||||||
|
|
||||||
|
|
||||||
class AddTagToArticleForm(forms.Form):
|
class AddTagForm(forms.Form):
|
||||||
"""Freeform tag-name entry — assigning an unknown name creates that tag
|
"""Freeform tag-name entry, used for tagging both articles and
|
||||||
for the user, so there's one flow instead of "create tag" then
|
subscriptions — assigning an unknown name creates that tag for the
|
||||||
"assign tag" as two separate steps."""
|
user, so there's one flow instead of "create tag" then "assign tag" as
|
||||||
|
two separate steps."""
|
||||||
|
|
||||||
tag_name = forms.CharField(max_length=100)
|
tag_name = forms.CharField(max_length=100)
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Generated by Django 5.2.18 on 2026-10-31 03:17
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('articles', '0001_initial'),
|
||||||
|
('feeds', '0001_initial'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SubscriptionTag',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('subscription', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subscription_tags', to='feeds.subscription')),
|
||||||
|
('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subscription_tags', to='articles.tag')),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'unique_together': {('user', 'subscription', 'tag')},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
+22
-1
@@ -1,7 +1,7 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from apps.feeds.models import Feed
|
from apps.feeds.models import Feed, Subscription
|
||||||
|
|
||||||
|
|
||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
@@ -89,3 +89,24 @@ class ArticleTag(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.article} -> {self.tag}"
|
return f"{self.article} -> {self.tag}"
|
||||||
|
|
||||||
|
|
||||||
|
class SubscriptionTag(models.Model):
|
||||||
|
"""Tags a feed itself (via the user's Subscription to it), independent
|
||||||
|
of tagging individual articles — e.g. tagging a whole feed "backend"
|
||||||
|
rather than tagging each of its articles one by one. Articles from a
|
||||||
|
tagged feed show up under that tag in the stream alongside any
|
||||||
|
individually-tagged articles (see apps.reader.views._apply_scope).
|
||||||
|
"""
|
||||||
|
|
||||||
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||||
|
subscription = models.ForeignKey(
|
||||||
|
Subscription, on_delete=models.CASCADE, related_name="subscription_tags"
|
||||||
|
)
|
||||||
|
tag = models.ForeignKey(Tag, on_delete=models.CASCADE, related_name="subscription_tags")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = [("user", "subscription", "tag")]
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.subscription} -> {self.tag}"
|
||||||
@@ -3,7 +3,7 @@ from django.http import Http404
|
|||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
|
|
||||||
from .forms import AddTagToArticleForm, TagForm
|
from .forms import AddTagForm, TagForm
|
||||||
from .models import Article, ArticleTag, Tag
|
from .models import Article, ArticleTag, Tag
|
||||||
|
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ def article_tags_partial(request, article_id):
|
|||||||
@require_POST
|
@require_POST
|
||||||
def add_tag_to_article(request, article_id):
|
def add_tag_to_article(request, article_id):
|
||||||
article = _owned_article(request.user, article_id)
|
article = _owned_article(request.user, article_id)
|
||||||
form = AddTagToArticleForm(request.POST)
|
form = AddTagForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
tag_name = form.cleaned_data["tag_name"].strip()
|
tag_name = form.cleaned_data["tag_name"].strip()
|
||||||
if tag_name:
|
if tag_name:
|
||||||
|
|||||||
+31
-1
@@ -1,6 +1,6 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
from .models import Folder
|
from .models import Folder, Subscription
|
||||||
|
|
||||||
|
|
||||||
class AddFeedForm(forms.Form):
|
class AddFeedForm(forms.Form):
|
||||||
@@ -13,5 +13,35 @@ class AddFeedForm(forms.Form):
|
|||||||
self.fields["folder"].queryset = Folder.objects.filter(user=user)
|
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):
|
class OPMLImportForm(forms.Form):
|
||||||
opml_file = forms.FileField(label="OPML file")
|
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.core.files.uploadedfile import SimpleUploadedFile
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from .models import Feed, Subscription
|
from .models import Feed, Folder, Subscription
|
||||||
from .test_opml import SIMPLE_OPML
|
from .test_opml import SIMPLE_OPML
|
||||||
|
|
||||||
User = get_user_model()
|
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()
|
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
|
@pytest.mark.django_db
|
||||||
def test_unsubscribe(client, alice, alices_subscription):
|
def test_unsubscribe(client, alice, alices_subscription):
|
||||||
client.login(username="alice", password="pw-alice-123")
|
client.login(username="alice", password="pw-alice-123")
|
||||||
|
|||||||
@@ -7,6 +7,26 @@ app_name = "feeds"
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("feeds/add/", views.add_feed, name="add_feed"),
|
path("feeds/add/", views.add_feed, name="add_feed"),
|
||||||
path("subscriptions/", views.subscription_list, name="subscription_list"),
|
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(
|
path(
|
||||||
"subscriptions/<int:subscription_id>/unsubscribe/",
|
"subscriptions/<int:subscription_id>/unsubscribe/",
|
||||||
views.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.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.views.decorators.http import require_POST
|
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 .models import Feed, Subscription
|
||||||
from .opml import export_opml, import_opml, parse_opml
|
from .opml import export_opml, import_opml, parse_opml
|
||||||
from .services.fetcher import fetch_and_ingest
|
from .services.fetcher import fetch_and_ingest
|
||||||
@@ -63,6 +66,59 @@ def subscription_list(request):
|
|||||||
return render(request, "feeds/subscriptions.html", {"subscriptions": subscriptions})
|
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
|
@login_required
|
||||||
@require_POST
|
@require_POST
|
||||||
def unsubscribe(request, subscription_id):
|
def unsubscribe(request, subscription_id):
|
||||||
|
|||||||
@@ -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()
|
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
|
@pytest.mark.django_db
|
||||||
def test_saved_filter_only_shows_saved_articles(client, alice, alices_article):
|
def test_saved_filter_only_shows_saved_articles(client, alice, alices_article):
|
||||||
client.login(username="alice", password="pw-alice-123")
|
client.login(username="alice", password="pw-alice-123")
|
||||||
|
|||||||
+21
-5
@@ -1,6 +1,7 @@
|
|||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.db.models import Q
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
@@ -50,9 +51,18 @@ def _apply_scope(request, queryset):
|
|||||||
if tag_id:
|
if tag_id:
|
||||||
active_tag = Tag.objects.filter(user=request.user, pk=tag_id).first()
|
active_tag = Tag.objects.filter(user=request.user, pk=tag_id).first()
|
||||||
if active_tag:
|
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(
|
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
|
active_feed = None
|
||||||
feed_id = request.GET.get("feed")
|
feed_id = request.GET.get("feed")
|
||||||
@@ -101,9 +111,15 @@ def _group_by_date(articles):
|
|||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def stream(request):
|
def stream(request):
|
||||||
active_filter = request.GET.get("filter", "unread")
|
requested_filter = request.GET.get("filter")
|
||||||
if active_filter not in VALID_FILTERS:
|
if requested_filter in VALID_FILTERS:
|
||||||
active_filter = "unread"
|
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)
|
queryset = _base_queryset(request.user)
|
||||||
if active_filter == "unread":
|
if active_filter == "unread":
|
||||||
|
|||||||
@@ -420,6 +420,8 @@ form p {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
border-radius: 0.25rem;
|
border-radius: 0.25rem;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 0.85rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon-btn:hover {
|
.icon-btn:hover {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
<ul class="sidebar-item-list">
|
<ul class="sidebar-item-list">
|
||||||
{% for tag in sidebar_tags %}
|
{% for tag in sidebar_tags %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'reader:stream' %}?filter=all&tag={{ tag.pk }}"
|
<a href="{% url 'reader:stream' %}?tag={{ tag.pk }}"
|
||||||
class="{% if request.GET.tag == tag.pk|stringformat:'s' %}active{% endif %}">{{ tag.name }}</a>
|
class="{% if request.GET.tag == tag.pk|stringformat:'s' %}active{% endif %}">{{ tag.name }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -43,13 +43,13 @@
|
|||||||
{% for entry in sidebar_folders %}
|
{% for entry in sidebar_folders %}
|
||||||
<details class="sidebar-section" open>
|
<details class="sidebar-section" open>
|
||||||
<summary>
|
<summary>
|
||||||
<a href="{% url 'reader:stream' %}?filter=all&folder={{ entry.folder.pk }}"
|
<a href="{% url 'reader:stream' %}?folder={{ entry.folder.pk }}"
|
||||||
class="sidebar-folder-link{% if request.GET.folder == entry.folder.pk|stringformat:'s' %} active{% endif %}">{{ entry.folder.name }}</a>
|
class="sidebar-folder-link{% if request.GET.folder == entry.folder.pk|stringformat:'s' %} active{% endif %}">{{ entry.folder.name }}</a>
|
||||||
</summary>
|
</summary>
|
||||||
<ul class="sidebar-item-list">
|
<ul class="sidebar-item-list">
|
||||||
{% for subscription in entry.subscriptions %}
|
{% for subscription in entry.subscriptions %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'reader:stream' %}?filter=all&feed={{ subscription.feed_id }}"
|
<a href="{% url 'reader:stream' %}?feed={{ subscription.feed_id }}"
|
||||||
class="sidebar-feed-link{% if request.GET.feed == subscription.feed_id|stringformat:'s' %} active{% endif %}">
|
class="sidebar-feed-link{% if request.GET.feed == subscription.feed_id|stringformat:'s' %} active{% endif %}">
|
||||||
{% if subscription.feed.favicon_url %}<img src="{{ subscription.feed.favicon_url }}" alt="" class="feed-favicon">{% endif %}
|
{% if subscription.feed.favicon_url %}<img src="{{ subscription.feed.favicon_url }}" alt="" class="feed-favicon">{% endif %}
|
||||||
<span>{{ subscription.display_title }}</span>
|
<span>{{ subscription.display_title }}</span>
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
<ul class="sidebar-item-list">
|
<ul class="sidebar-item-list">
|
||||||
{% for subscription in sidebar_unfoldered %}
|
{% for subscription in sidebar_unfoldered %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'reader:stream' %}?filter=all&feed={{ subscription.feed_id }}"
|
<a href="{% url 'reader:stream' %}?feed={{ subscription.feed_id }}"
|
||||||
class="sidebar-feed-link{% if request.GET.feed == subscription.feed_id|stringformat:'s' %} active{% endif %}">
|
class="sidebar-feed-link{% if request.GET.feed == subscription.feed_id|stringformat:'s' %} active{% endif %}">
|
||||||
{% if subscription.feed.favicon_url %}<img src="{{ subscription.feed.favicon_url }}" alt="" class="feed-favicon">{% endif %}
|
{% if subscription.feed.favicon_url %}<img src="{{ subscription.feed.favicon_url }}" alt="" class="feed-favicon">{% endif %}
|
||||||
<span>{{ subscription.display_title }}</span>
|
<span>{{ subscription.display_title }}</span>
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<div id="subscription-tags-{{ subscription.pk }}" class="article-tags">
|
||||||
|
{% for tag in tags %}
|
||||||
|
<span class="tag-pill" {% if tag.color %}style="--tag-color: {{ tag.color }};"{% endif %}>
|
||||||
|
{{ tag.name }}
|
||||||
|
<button
|
||||||
|
hx-post="{% url 'feeds:remove_tag_from_subscription' subscription.pk tag.pk %}"
|
||||||
|
hx-target="#subscription-tags-{{ subscription.pk }}"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
class="tag-remove" title="Remove tag">×</button>
|
||||||
|
</span>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<form
|
||||||
|
hx-post="{% url 'feeds:add_tag_to_subscription' subscription.pk %}"
|
||||||
|
hx-target="#subscription-tags-{{ subscription.pk }}"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
class="add-tag-form">
|
||||||
|
<input type="text" name="tag_name" placeholder="Add tag" list="subscription-user-tags-{{ subscription.pk }}" maxlength="100">
|
||||||
|
<button type="submit" class="icon-btn">Add</button>
|
||||||
|
</form>
|
||||||
|
<datalist id="subscription-user-tags-{{ subscription.pk }}">
|
||||||
|
{% for tag in all_user_tags %}
|
||||||
|
<option value="{{ tag.name }}">
|
||||||
|
{% endfor %}
|
||||||
|
</datalist>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Edit {{ subscription.display_title }} — Evection{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<p><a href="{% url 'feeds:subscription_list' %}">← Back to subscriptions</a></p>
|
||||||
|
<h1>Edit subscription</h1>
|
||||||
|
<p class="rule-summary">{{ subscription.feed.feed_url }}</p>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit">Save</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>Tags</h2>
|
||||||
|
<div
|
||||||
|
id="subscription-tags-{{ subscription.pk }}"
|
||||||
|
hx-get="{% url 'feeds:subscription_tags_partial' subscription.pk %}"
|
||||||
|
hx-trigger="load"
|
||||||
|
hx-swap="outerHTML"></div>
|
||||||
|
{% endblock %}
|
||||||
@@ -17,10 +17,13 @@
|
|||||||
<strong>{{ subscription.display_title }}</strong>
|
<strong>{{ subscription.display_title }}</strong>
|
||||||
{% if subscription.folder %}<span class="rule-summary">{{ subscription.folder.name }}</span>{% endif %}
|
{% if subscription.folder %}<span class="rule-summary">{{ subscription.folder.name }}</span>{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<form method="post" action="{% url 'feeds:unsubscribe' subscription.pk %}" class="inline-form">
|
<div class="rule-actions">
|
||||||
{% csrf_token %}
|
<a href="{% url 'feeds:edit_subscription' subscription.pk %}" class="icon-btn">Edit</a>
|
||||||
<button type="submit" class="icon-btn">Unsubscribe</button>
|
<form method="post" action="{% url 'feeds:unsubscribe' subscription.pk %}" class="inline-form">
|
||||||
</form>
|
{% csrf_token %}
|
||||||
|
<button type="submit" class="icon-btn">Unsubscribe</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<li class="empty-state">No subscriptions yet.</li>
|
<li class="empty-state">No subscriptions yet.</li>
|
||||||
|
|||||||
Reference in new issue
Block a user