Private
Public Access
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:
1 parent
3b58fdcb7e
commit
0e132e9ab9
24 files changed
+417
-307
No files matched your search
@@ -1,40 +1,50 @@
|
||||
from apps.articles.models import Tag, UserArticleState
|
||||
from apps.articles.models import SubscriptionTag, Tag, UserArticleState
|
||||
from apps.articles.queries import unread_counts_by_feed
|
||||
from apps.feeds.models import Folder, Subscription
|
||||
from apps.feeds.models import Subscription
|
||||
|
||||
|
||||
def sidebar(request):
|
||||
"""Folder/feed tree, tags, and starred count for the persistent sidebar
|
||||
rendered by base.html on every authenticated page. Kept out of
|
||||
individual views so every page gets the same sidebar for free.
|
||||
"""Tag/feed tree and starred count for the persistent sidebar rendered
|
||||
by base.html on every authenticated page. Kept out of individual views
|
||||
so every page gets the same sidebar for free.
|
||||
|
||||
Feeds are grouped by tag (a feed can appear under more than one, since
|
||||
SubscriptionTag is many-to-many — unlike the single-folder scheme this
|
||||
replaced); feeds with no tags at all fall into "untagged".
|
||||
"""
|
||||
user = getattr(request, "user", None)
|
||||
if user is None or not user.is_authenticated:
|
||||
return {}
|
||||
|
||||
unread_counts = unread_counts_by_feed(user)
|
||||
subscriptions = (
|
||||
Subscription.objects.filter(user=user)
|
||||
.select_related("feed", "folder")
|
||||
.order_by("order", "id")
|
||||
)
|
||||
tags = list(Tag.objects.filter(user=user))
|
||||
|
||||
folders = list(Folder.objects.filter(user=user).order_by("order", "name"))
|
||||
by_folder = {folder.pk: [] for folder in folders}
|
||||
unfoldered = []
|
||||
for subscription in subscriptions:
|
||||
tag_rows = (
|
||||
SubscriptionTag.objects.filter(user=user)
|
||||
.select_related("subscription__feed", "tag")
|
||||
.order_by("tag__name", "subscription__order", "subscription__id")
|
||||
)
|
||||
feeds_by_tag = {tag.pk: [] for tag in tags}
|
||||
tagged_subscription_ids = set()
|
||||
for row in tag_rows:
|
||||
subscription = row.subscription
|
||||
subscription.unread_count = unread_counts.get(subscription.feed_id, 0)
|
||||
if subscription.folder_id and subscription.folder_id in by_folder:
|
||||
by_folder[subscription.folder_id].append(subscription)
|
||||
else:
|
||||
unfoldered.append(subscription)
|
||||
feeds_by_tag.setdefault(row.tag_id, []).append(subscription)
|
||||
tagged_subscription_ids.add(subscription.pk)
|
||||
|
||||
untagged = []
|
||||
for subscription in (
|
||||
Subscription.objects.filter(user=user).select_related("feed").order_by("order", "id")
|
||||
):
|
||||
if subscription.pk not in tagged_subscription_ids:
|
||||
subscription.unread_count = unread_counts.get(subscription.feed_id, 0)
|
||||
untagged.append(subscription)
|
||||
|
||||
return {
|
||||
"sidebar_folders": [
|
||||
{"folder": folder, "subscriptions": by_folder[folder.pk]} for folder in folders
|
||||
"sidebar_tag_groups": [
|
||||
{"tag": tag, "subscriptions": feeds_by_tag.get(tag.pk, [])} for tag in tags
|
||||
],
|
||||
"sidebar_unfoldered": unfoldered,
|
||||
"sidebar_tags": Tag.objects.filter(user=user),
|
||||
"sidebar_untagged": untagged,
|
||||
"sidebar_starred_count": UserArticleState.objects.filter(
|
||||
user=user, is_starred=True
|
||||
).count(),
|
||||
|
||||
Reference in new issue
Block a user