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
+6
-4
@@ -1,6 +1,7 @@
|
||||
from django import forms
|
||||
|
||||
from apps.feeds.models import Feed, Folder
|
||||
from apps.articles.models import Tag
|
||||
from apps.feeds.models import Feed
|
||||
|
||||
from .models import FilterRule
|
||||
|
||||
@@ -11,7 +12,7 @@ class FilterRuleForm(forms.ModelForm):
|
||||
fields = [
|
||||
"name",
|
||||
"feed",
|
||||
"folder",
|
||||
"tag",
|
||||
"match_field",
|
||||
"match_type",
|
||||
"match_value",
|
||||
@@ -21,15 +22,16 @@ class FilterRuleForm(forms.ModelForm):
|
||||
"priority",
|
||||
"is_enabled",
|
||||
]
|
||||
labels = {"tag": "Scope to tag"}
|
||||
|
||||
def __init__(self, *args, user=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._user = user
|
||||
if user is not None:
|
||||
self.fields["feed"].queryset = Feed.objects.filter(subscriptions__user=user).distinct()
|
||||
self.fields["folder"].queryset = Folder.objects.filter(user=user)
|
||||
self.fields["tag"].queryset = Tag.objects.filter(user=user)
|
||||
self.fields["feed"].required = False
|
||||
self.fields["folder"].required = False
|
||||
self.fields["tag"].required = False
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def migrate_folder_scope_to_tag_scope(apps, schema_editor):
|
||||
FilterRule = apps.get_model("rules", "FilterRule")
|
||||
Tag = apps.get_model("articles", "Tag")
|
||||
|
||||
for rule in FilterRule.objects.exclude(folder__isnull=True).select_related("folder"):
|
||||
tag = Tag.objects.filter(user_id=rule.user_id, name=rule.folder.name[:100]).first()
|
||||
if tag is not None:
|
||||
rule.tag = tag
|
||||
rule.save(update_fields=["tag"])
|
||||
|
||||
|
||||
def noop_reverse(apps, schema_editor):
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("rules", "0001_initial"),
|
||||
("articles", "0003_migrate_folders_to_tags"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="filterrule",
|
||||
name="tag",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="articles.tag",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(migrate_folder_scope_to_tag_scope, noop_reverse),
|
||||
migrations.RemoveField(
|
||||
model_name="filterrule",
|
||||
name="folder",
|
||||
),
|
||||
]
|
||||
@@ -1,7 +1,8 @@
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
from apps.feeds.models import Feed, Folder
|
||||
from apps.articles.models import Tag
|
||||
from apps.feeds.models import Feed
|
||||
|
||||
|
||||
class FilterRule(models.Model):
|
||||
@@ -53,10 +54,11 @@ class FilterRule(models.Model):
|
||||
)
|
||||
name = models.CharField(max_length=255, blank=True)
|
||||
|
||||
# Scope: null means "every subscription", matching the plan's decision
|
||||
# to keep folders flat and scoping simple.
|
||||
# Scope: null means "every subscription". A tag-scoped rule applies to
|
||||
# any feed carrying that tag (via SubscriptionTag) — a feed can carry
|
||||
# more than one tag, unlike the single-folder scoping this replaced.
|
||||
feed = models.ForeignKey(Feed, null=True, blank=True, on_delete=models.CASCADE)
|
||||
folder = models.ForeignKey(Folder, null=True, blank=True, on_delete=models.CASCADE)
|
||||
tag = models.ForeignKey(Tag, null=True, blank=True, on_delete=models.CASCADE)
|
||||
|
||||
match_field = models.CharField(max_length=20, choices=MATCH_FIELD_CHOICES)
|
||||
match_type = models.CharField(max_length=20, choices=MATCH_TYPE_CHOICES)
|
||||
|
||||
+5
-5
@@ -10,7 +10,7 @@ from .models import FilterRule
|
||||
def reapply_rules_for_user_backlog(rule_id: int) -> int:
|
||||
"""Re-evaluates a user's full enabled ruleset (not just the triggering
|
||||
rule, so priority/short-circuit ordering stays correct) against their
|
||||
unread backlog, scoped by the triggering rule's own feed/folder scope.
|
||||
unread backlog, scoped by the triggering rule's own feed/tag scope.
|
||||
|
||||
Exists as a plain function so it can be called synchronously for
|
||||
immediate feedback (e.g. from a "Re-apply" view) or wrapped in a task
|
||||
@@ -25,11 +25,11 @@ def reapply_rules_for_user_backlog(rule_id: int) -> int:
|
||||
|
||||
if rule.feed_id:
|
||||
feed_ids = [rule.feed_id]
|
||||
elif rule.folder_id:
|
||||
elif rule.tag_id:
|
||||
feed_ids = list(
|
||||
Subscription.objects.filter(user=user, folder_id=rule.folder_id).values_list(
|
||||
"feed_id", flat=True
|
||||
)
|
||||
Subscription.objects.filter(
|
||||
user=user, subscription_tags__user=user, subscription_tags__tag_id=rule.tag_id
|
||||
).values_list("feed_id", flat=True)
|
||||
)
|
||||
else:
|
||||
feed_ids = list(Subscription.objects.filter(user=user).values_list("feed_id", flat=True))
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ from .tasks import reapply_rules_for_user_backlog
|
||||
|
||||
@login_required
|
||||
def rule_list(request):
|
||||
rules = FilterRule.objects.filter(user=request.user).select_related("feed", "folder")
|
||||
rules = FilterRule.objects.filter(user=request.user).select_related("feed", "tag")
|
||||
return render(request, "rules/rule_list.html", {"rules": rules})
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user