Remove folders; feeds are organized by tags now

Folders are gone — organization is tags-only, via the SubscriptionTag
model added last commit. A migration converts every existing Folder into
a same-named Tag applied to its feeds, and every folder-scoped FilterRule
into an equivalent tag-scoped one, before the Folder table is dropped, so
upgrading an existing instance loses nothing (verified by seeding the
pre-removal schema directly and running the migration chain against it).

Unlike folders, a feed can carry more than one tag, so:
- apps.articles.tasks.apply_filter_rules_for_feed and apps.rules.tasks's
  backlog re-apply now scope by "does this feed carry tag X" rather than
  "does this feed belong to folder X".
- apps.feeds.opml: a feed's tags export as a comma-separated "category"
  attribute (the standard OPML way to represent multiple categories)
  instead of nesting under one folder outline. Import reads both that
  attribute and nested category outlines, turning each enclosing level
  into its own tag rather than collapsing to the nearest one.
- The sidebar groups feeds by tag instead of folder, so a feed with two
  tags now appears in both groups; untagged feeds fall into "Untagged".

AddFeedForm gained a comma-separated tag_names field for parity with the
old add-time folder picker. EditSubscriptionForm dropped its folder
field entirely — tagging a subscription happens through the tag editor
already on that page.

Verified end to end: the migration chain from empty, the data migration
against a seeded pre-removal schema (folder/subscription/rule all convert
correctly), and the running app's sidebar grouping, OPML export category
attributes, and tag editor.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ksmithandClaude Sonnet 5 committed 2026-10-30 21:30:06 -06:00
1 parent 3b58fdcb7e
commit 0e132e9ab9
24 files changed
+417 -307

No files matched your search

@@ -0,0 +1,32 @@
from django.db import migrations
def migrate_folders_to_tags(apps, schema_editor):
Folder = apps.get_model("feeds", "Folder")
Tag = apps.get_model("articles", "Tag")
SubscriptionTag = apps.get_model("articles", "SubscriptionTag")
for folder in Folder.objects.all():
tag, _ = Tag.objects.get_or_create(user_id=folder.user_id, name=folder.name[:100])
for subscription in folder.subscriptions.all():
SubscriptionTag.objects.get_or_create(
user_id=folder.user_id, subscription=subscription, tag=tag
)
def noop_reverse(apps, schema_editor):
# Folders are gone by the time anyone would reverse this; nothing to
# restore them from.
pass
class Migration(migrations.Migration):
dependencies = [
("articles", "0002_subscriptiontag"),
("feeds", "0001_initial"),
]
operations = [
migrations.RunPython(migrate_folders_to_tags, noop_reverse),
]
+10 -5
View File
@@ -5,13 +5,13 @@ from apps.feeds.models import Subscription
from apps.rules.engine import evaluate_rules_for_article
from apps.rules.models import FilterRule
from .models import Article
from .models import Article, SubscriptionTag
@shared_task
def apply_filter_rules_for_feed(feed_id: int, article_ids: list[int]):
"""For every subscriber of ``feed_id``, evaluate their enabled
FilterRules (scoped to this feed/folder or unscoped) against the given
FilterRules (scoped to this feed/tag or unscoped) against the given
articles. Dispatched by the fetch pipeline after new/updated articles
are committed for a feed.
"""
@@ -29,10 +29,15 @@ def apply_filter_rules_for_feed(feed_id: int, article_ids: list[int]):
rules = FilterRule.objects.filter(user=subscription.user, is_enabled=True).filter(
Q(feed_id=feed_id) | Q(feed__isnull=True)
)
if subscription.folder_id:
rules = rules.filter(Q(folder_id=subscription.folder_id) | Q(folder__isnull=True))
subscription_tag_ids = list(
SubscriptionTag.objects.filter(
user=subscription.user, subscription=subscription
).values_list("tag_id", flat=True)
)
if subscription_tag_ids:
rules = rules.filter(Q(tag_id__in=subscription_tag_ids) | Q(tag__isnull=True))
else:
rules = rules.filter(folder__isnull=True)
rules = rules.filter(tag__isnull=True)
rules = list(rules.order_by("priority", "id"))
if not rules:
continue
+38 -14
View File
@@ -1,10 +1,10 @@
import pytest
from django.contrib.auth import get_user_model
from apps.feeds.models import Feed, Folder, Subscription
from apps.feeds.models import Feed, Subscription
from apps.rules.models import FilterRule
from .models import Article, UserArticleState
from .models import Article, SubscriptionTag, Tag, UserArticleState
from .tasks import apply_filter_rules_for_feed
User = get_user_model()
@@ -72,31 +72,55 @@ def test_feed_scoped_rule_does_not_apply_to_other_feeds(alice):
@pytest.mark.django_db
def test_folder_scoped_rule_only_applies_within_that_folder(alice, feed):
def test_tag_scoped_rule_only_applies_to_feeds_carrying_that_tag(alice, feed):
other_feed = Feed.objects.create(feed_url="https://other.example.com/feed.xml")
folder = Folder.objects.create(user=alice, name="Tech")
Subscription.objects.create(user=alice, feed=feed, folder=folder)
Subscription.objects.create(user=alice, feed=other_feed, folder=None)
tagged_sub = Subscription.objects.create(user=alice, feed=feed)
Subscription.objects.create(user=alice, feed=other_feed)
tag = Tag.objects.create(user=alice, name="Tech")
SubscriptionTag.objects.create(user=alice, subscription=tagged_sub, tag=tag)
FilterRule.objects.create(
user=alice,
folder=folder,
tag=tag,
match_field=FilterRule.FIELD_TITLE,
match_type=FilterRule.MATCH_CONTAINS,
match_value="Python",
action=FilterRule.ACTION_STAR,
)
in_folder_article = Article.objects.create(feed=feed, guid="guid-1", title="Python in folder")
outside_folder_article = Article.objects.create(
feed=other_feed, guid="guid-2", title="Python outside folder"
tagged_article = Article.objects.create(feed=feed, guid="guid-1", title="Python in tagged feed")
untagged_article = Article.objects.create(
feed=other_feed, guid="guid-2", title="Python in untagged feed"
)
apply_filter_rules_for_feed(feed.id, [in_folder_article.pk])
apply_filter_rules_for_feed(other_feed.id, [outside_folder_article.pk])
apply_filter_rules_for_feed(feed.id, [tagged_article.pk])
apply_filter_rules_for_feed(other_feed.id, [untagged_article.pk])
assert UserArticleState.objects.get(user=alice, article=in_folder_article).is_starred is True
assert not UserArticleState.objects.filter(user=alice, article=outside_folder_article).exists()
assert UserArticleState.objects.get(user=alice, article=tagged_article).is_starred is True
assert not UserArticleState.objects.filter(user=alice, article=untagged_article).exists()
@pytest.mark.django_db
def test_rule_scoped_to_one_tag_still_applies_to_a_feed_with_multiple_tags(alice, feed):
subscription = Subscription.objects.create(user=alice, feed=feed)
tech_tag = Tag.objects.create(user=alice, name="Tech")
news_tag = Tag.objects.create(user=alice, name="News")
SubscriptionTag.objects.create(user=alice, subscription=subscription, tag=tech_tag)
SubscriptionTag.objects.create(user=alice, subscription=subscription, tag=news_tag)
FilterRule.objects.create(
user=alice,
tag=news_tag,
match_field=FilterRule.FIELD_TITLE,
match_type=FilterRule.MATCH_CONTAINS,
match_value="Python",
action=FilterRule.ACTION_STAR,
)
article = Article.objects.create(feed=feed, guid="guid-1", title="Python news")
apply_filter_rules_for_feed(feed.id, [article.pk])
assert UserArticleState.objects.get(user=alice, article=article).is_starred is True
@pytest.mark.django_db