Private
Public Access
Implements FilterRule (one condition -> action, scoped to a feed and/or folder or global) with an evaluation engine applied at ingest time: after the fetch pipeline commits new/updated articles, each affected subscriber's enabled rules run in priority order against them, with tag/star/mark_read actions stacking and hide short-circuiting further evaluation for that article. Adds rule management (create/edit/delete) and a "Re-apply" action that re-evaluates a user's full ruleset against their unread backlog, scoped by the triggering rule's own feed/folder — so a newly added rule can retroactively affect already-ingested articles, not just future ones. Verified live in-browser: created a "title contains 'Show HN' -> star" rule scoped to the subscribed Hacker News feed, re-applied it against the existing unread backlog, and confirmed both matching articles were starred. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
from django import forms
|
|
|
|
from apps.feeds.models import Feed, Folder
|
|
|
|
from .models import FilterRule
|
|
|
|
|
|
class FilterRuleForm(forms.ModelForm):
|
|
class Meta:
|
|
model = FilterRule
|
|
fields = [
|
|
"name",
|
|
"feed",
|
|
"folder",
|
|
"match_field",
|
|
"match_type",
|
|
"match_value",
|
|
"case_sensitive",
|
|
"action",
|
|
"action_value",
|
|
"priority",
|
|
"is_enabled",
|
|
]
|
|
|
|
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["feed"].required = False
|
|
self.fields["folder"].required = False
|
|
|
|
def clean(self):
|
|
cleaned_data = super().clean()
|
|
if (
|
|
cleaned_data.get("action") == FilterRule.ACTION_TAG
|
|
and not cleaned_data.get("action_value", "").strip()
|
|
):
|
|
self.add_error("action_value", "Required when the action is 'Add tag'.")
|
|
return cleaned_data
|
|
|
|
def save(self, commit=True):
|
|
rule = super().save(commit=False)
|
|
if self._user is not None:
|
|
rule.user = self._user
|
|
if commit:
|
|
rule.save()
|
|
return rule
|