Private
Public Access
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>
82 lines
2.8 KiB
Python
82 lines
2.8 KiB
Python
from django.conf import settings
|
|
from django.db import models
|
|
|
|
from apps.articles.models import Tag
|
|
from apps.feeds.models import Feed
|
|
|
|
|
|
class FilterRule(models.Model):
|
|
"""A single condition -> action rule, evaluated at ingest time against
|
|
new/updated articles for every subscriber of the matching feed(s).
|
|
|
|
v1 supports one condition per rule; users combine effects by stacking
|
|
multiple rules (evaluated in ``priority`` order, ascending — lower
|
|
numbers run first). Compound AND/OR condition groups are deferred.
|
|
"""
|
|
|
|
FIELD_TITLE = "title"
|
|
FIELD_CONTENT = "content"
|
|
FIELD_AUTHOR = "author"
|
|
FIELD_FEED_TITLE = "feed_title"
|
|
FIELD_URL = "url"
|
|
MATCH_FIELD_CHOICES = [
|
|
(FIELD_TITLE, "Title"),
|
|
(FIELD_CONTENT, "Content"),
|
|
(FIELD_AUTHOR, "Author"),
|
|
(FIELD_FEED_TITLE, "Feed"),
|
|
(FIELD_URL, "URL"),
|
|
]
|
|
|
|
MATCH_CONTAINS = "contains"
|
|
MATCH_NOT_CONTAINS = "not_contains"
|
|
MATCH_REGEX = "regex"
|
|
MATCH_EXACT = "exact"
|
|
MATCH_TYPE_CHOICES = [
|
|
(MATCH_CONTAINS, "Contains"),
|
|
(MATCH_NOT_CONTAINS, "Does not contain"),
|
|
(MATCH_REGEX, "Regex"),
|
|
(MATCH_EXACT, "Exact match"),
|
|
]
|
|
|
|
ACTION_TAG = "tag"
|
|
ACTION_STAR = "star"
|
|
ACTION_HIDE = "hide"
|
|
ACTION_MARK_READ = "mark_read"
|
|
ACTION_CHOICES = [
|
|
(ACTION_TAG, "Add tag"),
|
|
(ACTION_STAR, "Star"),
|
|
(ACTION_HIDE, "Hide"),
|
|
(ACTION_MARK_READ, "Mark read"),
|
|
]
|
|
|
|
user = models.ForeignKey(
|
|
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="filter_rules"
|
|
)
|
|
name = models.CharField(max_length=255, blank=True)
|
|
|
|
# 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)
|
|
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)
|
|
match_value = models.CharField(max_length=500)
|
|
case_sensitive = models.BooleanField(default=False)
|
|
|
|
action = models.CharField(max_length=20, choices=ACTION_CHOICES)
|
|
action_value = models.CharField(
|
|
max_length=100, blank=True, help_text="Tag name, only used when action is 'Add tag'."
|
|
)
|
|
|
|
priority = models.PositiveIntegerField(default=0, help_text="Lower numbers run first.")
|
|
is_enabled = models.BooleanField(default=True)
|
|
|
|
class Meta:
|
|
ordering = ["priority", "id"]
|
|
|
|
def __str__(self):
|
|
label = self.name or f"{self.get_match_field_display()} {self.get_match_type_display()}"
|
|
return f"{label} -> {self.get_action_display()}"
|