From 16ffd8e75ae0637489ad15138c74641b0317f4a7 Mon Sep 17 00:00:00 2001 From: Jordan Robinson Date: Wed, 17 Sep 2025 21:33:06 +0100 Subject: [PATCH] add atom feed --- main/denylist.py | 1 + main/feeds.py | 18 +++- main/templates/main/analytic_list.html | 1 + main/templates/main/blog_index.html | 1 + main/tests/test_analytics.py | 44 ++++++--- main/tests/test_feeds.py | 121 ++++++++++++------------- main/urls.py | 5 +- 7 files changed, 112 insertions(+), 79 deletions(-) diff --git a/main/denylist.py b/main/denylist.py index ba7ab397d58cd671f0540e7b30e1cfcfe2d1ebb2..b83a6b65bb10ee01a59ab728c84bafb9c8b77c7c 100644 --- a/main/denylist.py +++ b/main/denylist.py @@ -8,6 +8,7 @@ DISALLOWED_USERNAMES = [ "administration", "administrator", "api", + "atom", "auth", "authentication", "billing", diff --git a/main/feeds.py b/main/feeds.py index e7085105e4445e81bc029781bc01aee17063bb61..cb2d3a95a8b49c932dad4e042f7f048004f0618a 100644 --- a/main/feeds.py +++ b/main/feeds.py @@ -7,7 +7,7 @@ from django.utils import timezone from main import models from main.util import reading_time -from django.utils.feedgenerator import Rss201rev2Feed +from django.utils.feedgenerator import Rss201rev2Feed, Atom1Feed class RSLRSSFeed(Rss201rev2Feed): def root_attributes(self): @@ -60,7 +60,6 @@ class RSLRSSFeed(Rss201rev2Feed): handler.endElement("rsl:license") handler.endElement("rsl:content") - class RSSBlogFeed(Feed): feed_type = RSLRSSFeed title = "" @@ -120,6 +119,21 @@ class RSSBlogFeed(Feed): return {"rsl_content": rsl_content} return {} + +class AtomBlogFeed(RSSBlogFeed): + feed_type = Atom1Feed + subtitle = RSSBlogFeed.description + + def __call__(self, request, *args, **kwargs): + if not hasattr(request, "subdomain"): + raise Http404() + + user = models.User.objects.get(username=request.subdomain) + + models.AnalyticPage.objects.create(user=user, path="atom") + + return super().__call__(request, *args, **kwargs) + # Helper to parse RSL XML RSL_NS = {"rsl": "https://rslstandard.org/rsl"} diff --git a/main/templates/main/analytic_list.html b/main/templates/main/analytic_list.html index 3fd7a7d76cbb739701d4cef92fa2612a7fd68bfe..7004d6e3769d829ded9dffc9850877568624fab4 100644 --- a/main/templates/main/analytic_list.html +++ b/main/templates/main/analytic_list.html @@ -11,6 +11,7 @@