aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/feeds.py
diff options
context:
space:
mode:
authorBen Sturmfels <ben@sturm.com.au>2021-03-15 23:24:44 +1100
committerBen Sturmfels <ben@sturm.com.au>2021-03-16 12:17:57 +1100
commit2d941d21e131a4cd228b436706ded084d537b9c8 (patch)
tree2f0a9ea4dd33727ce4f9cc889baafe14ef3c0a34 /mediagoblin/tools/feeds.py
parent6d3d8667aec55fa18e6c2c92224ec02a42f3521d (diff)
downloadmediagoblin-2d941d21e131a4cd228b436706ded084d537b9c8.tar.lz
mediagoblin-2d941d21e131a4cd228b436706ded084d537b9c8.tar.xz
mediagoblin-2d941d21e131a4cd228b436706ded084d537b9c8.zip
Convert atom feeds to use feedgenerator library.
Issue is that Werkzeug > 1.0.0 has removed werkzeug.contrib.atom.AtomFeed, making it difficult to use a distribution-packaged version of werkzeug. To solve this, I've replaced use of werkzeug.contrib.atom.AtomFeed with feedgenerator.Atom1Feed. After the change, the only major difference between the feeds before and after is that they use <summary> instead of <content>. Minor differences include no longer adding 'type="text/html"' on some <link> elements and no "xml:base" attribute on <entry> elements. I don't think these differences will have any noticable effect. Tested on Liferea feed reader.
Diffstat (limited to 'mediagoblin/tools/feeds.py')
-rw-r--r--mediagoblin/tools/feeds.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/mediagoblin/tools/feeds.py b/mediagoblin/tools/feeds.py
new file mode 100644
index 00000000..c62478c4
--- /dev/null
+++ b/mediagoblin/tools/feeds.py
@@ -0,0 +1,38 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2021 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from feedgenerator.django.utils import feedgenerator
+
+
+class AtomFeedWithLinks(feedgenerator.Atom1Feed):
+ """Custom AtomFeed that adds additional top-level links.
+
+ This is used in MediaGoblin for adding pubsubhubub "hub" links to the feed
+ via the "push_urls" config. We're porting the feed across to feedgenerator
+ due to deprecation of werkzeug.contrib.atom.AtomFeed, so while I've never
+ seen this feature in use, but this class allows us to continue to support
+ it.
+
+ """
+ def __init__(self, *args, links=None, **kwargs):
+ super().__init__(*args, **kwargs)
+ links = [] if links is None else links
+ self.links = links
+
+ def add_root_elements(self, handler):
+ super().add_root_elements(handler)
+ for link in self.links:
+ handler.addQuickElement('link', '', link)