Private
Public Access
Add OPML import/export and a subscriptions management page
Implements OPML parsing with defusedxml (untrusted upload, XXE risk) and export with the stdlib's plain ElementTree (trusted, app-generated output). Nesting deeper than one level flattens into its nearest enclosing folder, matching the app's flat-folder model. Import reuses existing Feed/Subscription rows via get_or_create, so re-importing the same file is idempotent and cross-user Feed dedup is preserved. Large imports (>50 entries) dispatch to a Celery task instead of blocking the request; newly imported feeds aren't fetched immediately since they have no last_fetched_at, so the next poll_due_feeds beat cycle picks them up naturally. Adds a Subscriptions page (replacing the standalone "Add feed" link in nav) listing current subscriptions with unsubscribe, plus Import/ Export OPML actions. Verified live: imported a 2-feed/1-folder OPML file against the running dev server (via an authenticated session, since this browser tool has no file-picker automation), confirmed the resulting subscriptions and folder in the UI, exported and inspected the resulting OPML structure, and unsubscribed from one feed. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8653dbeaf9
commit
ea214dd9ce
11 files changed
+533
-3
No files matched your search
@@ -1,12 +1,15 @@
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
from io import BytesIO
|
||||
|
||||
from celery import shared_task
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.utils import timezone
|
||||
|
||||
from apps.articles.tasks import apply_filter_rules_for_feed
|
||||
|
||||
from .models import Feed
|
||||
from .opml import import_opml
|
||||
from .services.fetcher import effective_interval_minutes, fetch_and_ingest
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -69,3 +72,15 @@ def reset_feed_backoff(feed_id: int):
|
||||
"""Admin-triggered: clear a feed's error count so it's retried at its
|
||||
normal configured interval instead of the backed-off one."""
|
||||
Feed.objects.filter(pk=feed_id).update(fetch_error_count=0)
|
||||
|
||||
|
||||
@shared_task
|
||||
def import_opml_task(user_id: int, opml_content: str):
|
||||
"""Background path for large OPML imports — see OPML_ASYNC_THRESHOLD
|
||||
in apps.feeds.views. opml_content is passed as text rather than a
|
||||
file handle since Celery tasks must be JSON-serializable."""
|
||||
try:
|
||||
user = get_user_model().objects.get(pk=user_id)
|
||||
except get_user_model().DoesNotExist:
|
||||
return None
|
||||
return import_opml(user, BytesIO(opml_content.encode("utf-8")))
|
||||
Reference in new issue
Block a user