2024-04-14 14:48:07 +00:00
|
|
|
from django.contrib.syndication.views import Feed
|
2024-04-15 21:08:39 +00:00
|
|
|
from django.utils.feedgenerator import Rss201rev2Feed
|
2024-04-15 22:18:47 +00:00
|
|
|
from django.templatetags.static import static
|
2024-04-15 21:08:39 +00:00
|
|
|
from django.utils.xmlutils import SimplerXMLGenerator
|
|
|
|
|
2024-04-14 14:48:07 +00:00
|
|
|
from .models import AdoptionNotice
|
|
|
|
|
|
|
|
|
2024-04-15 21:08:39 +00:00
|
|
|
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()
|
2024-04-15 22:18:47 +00:00
|
|
|
handler._write(f'<?xml-stylesheet href="{static("rss.xsl")}" type="text/xsl"?>')
|
2024-04-15 21:08:39 +00:00
|
|
|
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")
|
|
|
|
|
|
|
|
|
2024-04-14 14:48:07 +00:00
|
|
|
class LatestAdoptionNoticesFeed(Feed):
|
2024-04-15 21:08:39 +00:00
|
|
|
feed_type = FormattedFeed
|
2024-04-14 14:48:27 +00:00
|
|
|
title = "Notfellchen"
|
2024-04-14 14:48:07 +00:00
|
|
|
link = "/rss/"
|
|
|
|
description = "Updates zu neuen Vermittlungen."
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return AdoptionNotice.objects.order_by("-created_at")[:5]
|
|
|
|
|
|
|
|
def item_title(self, item):
|
|
|
|
return item.name
|
|
|
|
|
|
|
|
def item_description(self, item):
|
|
|
|
return item.description
|