2018-05-10 22:52:29 -04:00
|
|
|
from django.conf import settings
|
2017-10-31 18:29:59 -04:00
|
|
|
from django.contrib.sites.models import Site
|
|
|
|
from django.contrib.syndication.views import Feed
|
|
|
|
from django.urls import reverse
|
|
|
|
from django.utils.feedgenerator import Atom1Feed
|
|
|
|
from urllib.parse import urljoin
|
2017-10-31 18:32:42 -04:00
|
|
|
from lemoncurry.templatetags.markdown import markdown
|
2018-05-08 04:10:08 -04:00
|
|
|
from ..kinds import on_home
|
2018-03-06 23:46:21 -05:00
|
|
|
from ..models import Entry
|
2017-10-31 18:29:59 -04:00
|
|
|
|
|
|
|
|
2018-05-10 22:52:29 -04:00
|
|
|
class Atom1FeedWithHub(Atom1Feed):
|
|
|
|
def add_root_elements(self, handler):
|
|
|
|
super().add_root_elements(handler)
|
|
|
|
handler.startElement('link', {'rel': 'hub', 'href': settings.PUSH_HUB})
|
|
|
|
handler.endElement('link')
|
|
|
|
|
|
|
|
|
2017-10-31 18:29:59 -04:00
|
|
|
class EntriesFeed(Feed):
|
|
|
|
def item_title(self, entry):
|
|
|
|
return entry.title
|
|
|
|
|
|
|
|
def item_description(self, entry):
|
2017-10-31 18:32:42 -04:00
|
|
|
return markdown(entry.content)
|
2017-10-31 18:29:59 -04:00
|
|
|
|
|
|
|
def item_author_name(self, entry):
|
|
|
|
return entry.author.name
|
|
|
|
|
|
|
|
def item_author_email(self, entry):
|
|
|
|
return entry.author.email
|
|
|
|
|
|
|
|
def item_author_link(self, entry):
|
|
|
|
base = 'https://' + Site.objects.get_current().domain
|
|
|
|
return urljoin(base, entry.author.url)
|
|
|
|
|
|
|
|
def item_pubdate(self, entry):
|
|
|
|
return entry.published
|
|
|
|
|
|
|
|
def item_updatedate(self, entry):
|
|
|
|
return entry.updated
|
|
|
|
|
2017-12-04 06:19:03 -05:00
|
|
|
def item_categories(self, entry):
|
|
|
|
return (cat.name for cat in entry.cats.all())
|
|
|
|
|
2017-10-31 18:29:59 -04:00
|
|
|
|
|
|
|
class RssByKind(EntriesFeed):
|
2018-03-07 21:49:02 -05:00
|
|
|
def get_object(self, request, kind):
|
2018-05-08 04:10:08 -04:00
|
|
|
return kind
|
2017-10-31 18:29:59 -04:00
|
|
|
|
2018-03-07 21:49:02 -05:00
|
|
|
def title(self, kind):
|
2017-10-31 18:29:59 -04:00
|
|
|
return "{0} ~ {1}".format(
|
2018-03-07 21:49:02 -05:00
|
|
|
kind.plural,
|
2017-10-31 18:29:59 -04:00
|
|
|
Site.objects.get_current().name,
|
|
|
|
)
|
|
|
|
|
2018-03-07 21:49:02 -05:00
|
|
|
def link(self, kind):
|
|
|
|
return kind.index
|
2017-10-31 18:29:59 -04:00
|
|
|
|
2018-03-07 21:49:02 -05:00
|
|
|
def description(self, kind):
|
2017-10-31 18:29:59 -04:00
|
|
|
return "all {0} at {1}".format(
|
2018-03-07 21:49:02 -05:00
|
|
|
kind.plural,
|
2017-10-31 18:29:59 -04:00
|
|
|
Site.objects.get_current().name,
|
|
|
|
)
|
|
|
|
|
2018-03-07 21:49:02 -05:00
|
|
|
def items(self, kind):
|
|
|
|
return Entry.objects.filter(kind=kind.id)
|
2017-10-31 18:29:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
class AtomByKind(RssByKind):
|
2018-05-10 22:52:29 -04:00
|
|
|
feed_type = Atom1FeedWithHub
|
2017-10-31 18:29:59 -04:00
|
|
|
subtitle = RssByKind.description
|
|
|
|
|
|
|
|
|
2017-11-12 21:16:46 -05:00
|
|
|
class RssHomeEntries(EntriesFeed):
|
2017-10-31 18:29:59 -04:00
|
|
|
def title(self):
|
|
|
|
return Site.objects.get_current().name
|
|
|
|
|
|
|
|
def link(self):
|
|
|
|
return reverse('home:index')
|
|
|
|
|
|
|
|
def description(self):
|
|
|
|
return "content from {0}".format(
|
|
|
|
Site.objects.get_current().name,
|
|
|
|
)
|
|
|
|
|
|
|
|
def items(self):
|
2017-11-12 21:16:46 -05:00
|
|
|
return Entry.objects.filter(kind__in=on_home)
|
2017-10-31 18:29:59 -04:00
|
|
|
|
|
|
|
|
2017-11-12 21:16:46 -05:00
|
|
|
class AtomHomeEntries(RssHomeEntries):
|
2018-05-10 22:52:29 -04:00
|
|
|
feed_type = Atom1FeedWithHub
|
2017-11-12 21:16:46 -05:00
|
|
|
subtitle = RssHomeEntries.description
|