/unsubscribe/",
+ views.unsubscribe,
+ name="unsubscribe",
+ ),
+ path("subscriptions/import/", views.import_opml_view, name="import_opml"),
+ path("subscriptions/export/", views.export_opml_view, name="export_opml"),
]
diff --git a/apps/feeds/views.py b/apps/feeds/views.py
index 3559584..08bb5bc 100644
--- a/apps/feeds/views.py
+++ b/apps/feeds/views.py
@@ -1,10 +1,18 @@
+from io import BytesIO
+
from django.contrib import messages
from django.contrib.auth.decorators import login_required
-from django.shortcuts import redirect, render
+from django.http import HttpResponse
+from django.shortcuts import get_object_or_404, redirect, render
+from django.views.decorators.http import require_POST
-from .forms import AddFeedForm
+from .forms import AddFeedForm, OPMLImportForm
from .models import Feed, Subscription
+from .opml import export_opml, import_opml, parse_opml
from .services.fetcher import fetch_and_ingest
+from .tasks import import_opml_task
+
+OPML_ASYNC_THRESHOLD = 50
@login_required
@@ -43,3 +51,57 @@ def add_feed(request):
return redirect("reader:stream")
return render(request, "feeds/add_feed.html", {"form": form})
+
+
+@login_required
+def subscription_list(request):
+ subscriptions = (
+ Subscription.objects.filter(user=request.user)
+ .select_related("feed", "folder")
+ .order_by("folder__name", "order", "id")
+ )
+ return render(request, "feeds/subscriptions.html", {"subscriptions": subscriptions})
+
+
+@login_required
+@require_POST
+def unsubscribe(request, subscription_id):
+ subscription = get_object_or_404(Subscription, user=request.user, pk=subscription_id)
+ title = subscription.display_title
+ subscription.delete()
+ messages.success(request, f"Unsubscribed from '{title}'.")
+ return redirect("feeds:subscription_list")
+
+
+@login_required
+def import_opml_view(request):
+ form = OPMLImportForm(request.POST or None, request.FILES or None)
+ if request.method == "POST" and form.is_valid():
+ content = form.cleaned_data["opml_file"].read()
+ try:
+ entry_count = len(parse_opml(BytesIO(content)))
+ except Exception:
+ messages.error(request, "That file doesn't look like a valid OPML export.")
+ return redirect("feeds:import_opml")
+
+ if entry_count > OPML_ASYNC_THRESHOLD:
+ import_opml_task.delay(request.user.id, content.decode("utf-8"))
+ messages.success(request, f"Importing {entry_count} feeds in the background.")
+ else:
+ result = import_opml(request.user, BytesIO(content))
+ messages.success(
+ request,
+ f"Imported {result['created']} feed(s) "
+ f"({result['already_subscribed']} already subscribed).",
+ )
+ return redirect("feeds:subscription_list")
+
+ return render(request, "feeds/import_opml.html", {"form": form})
+
+
+@login_required
+def export_opml_view(request):
+ content = export_opml(request.user)
+ response = HttpResponse(content, content_type="text/x-opml")
+ response["Content-Disposition"] = 'attachment; filename="evection-subscriptions.opml"'
+ return response
diff --git a/static/css/base.css b/static/css/base.css
index cd52bf7..039d831 100644
--- a/static/css/base.css
+++ b/static/css/base.css
@@ -245,6 +245,20 @@ input, button {
margin: 1rem 0;
}
+.subscription-list {
+ list-style: none;
+ padding: 0;
+}
+
+.subscription-row {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ gap: 1rem;
+ padding: 0.5rem 0;
+ border-bottom: 1px solid #eee;
+}
+
.search-form input {
flex: 1;
}
diff --git a/templates/feeds/import_opml.html b/templates/feeds/import_opml.html
new file mode 100644
index 0000000..2758b05
--- /dev/null
+++ b/templates/feeds/import_opml.html
@@ -0,0 +1,12 @@
+{% extends "base.html" %}
+{% block title %}Import OPML — Evection{% endblock %}
+{% block content %}
+ ← Back to subscriptions
+ Import OPML
+ Upload an OPML file exported from FreshRSS or another feed reader.
+
+{% endblock %}
diff --git a/templates/feeds/subscriptions.html b/templates/feeds/subscriptions.html
new file mode 100644
index 0000000..64a534f
--- /dev/null
+++ b/templates/feeds/subscriptions.html
@@ -0,0 +1,29 @@
+{% extends "base.html" %}
+{% block title %}Subscriptions — Evection{% endblock %}
+{% block content %}
+ ← Back to stream
+ Subscriptions
+
+
+ Add feed
+ · Import OPML
+ · Export OPML
+
+
+
+{% endblock %}
diff --git a/templates/reader/stream.html b/templates/reader/stream.html
index a67aba4..4446fb3 100644
--- a/templates/reader/stream.html
+++ b/templates/reader/stream.html
@@ -4,7 +4,7 @@