feat: Allow styling of RSS feed

This commit is contained in:
2024-04-15 23:08:39 +02:00
parent a2058a4cfe
commit c1b0a4195a
2 changed files with 243 additions and 1 deletions

View File

@@ -1,10 +1,31 @@
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Rss201rev2Feed
from django.urls import reverse
from django.utils.xmlutils import SimplerXMLGenerator
from .models import AdoptionNotice
class FormattedFeed(Rss201rev2Feed):
"""
"""
content_type = "text/xml; charset=utf-8"
def write(self, outfile, encoding):
handler = SimplerXMLGenerator(outfile, encoding, short_empty_elements=True)
handler.startDocument()
handler._write('<?xml-stylesheet href="/static/rss.xsl" type="text/xsl"?>')
handler.startElement("rss", self.rss_attributes())
handler.startElement("channel", self.root_attributes())
self.add_root_elements(handler)
self.write_items(handler)
self.endChannelElement(handler)
handler.endElement("rss")
class LatestAdoptionNoticesFeed(Feed):
feed_type = FormattedFeed
title = "Notfellchen"
link = "/rss/"
description = "Updates zu neuen Vermittlungen."
@@ -17,4 +38,3 @@ class LatestAdoptionNoticesFeed(Feed):
def item_description(self, item):
return item.description