-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathfeeds.py
More file actions
63 lines (47 loc) · 1.88 KB
/
Copy pathfeeds.py
File metadata and controls
63 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from datetime import datetime, timezone
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Atom1Feed
from django.utils.timezone import make_aware
from django.utils.html import urlize, linebreaks
from .models import Entry
class RSSNewsFeed(Feed):
"""An RSS feed for Entry ("News" in the UI) items"""
title = "News"
link = "/news/"
description = "Recent news for Boost C++ Libraries."
def items(self):
return Entry.objects.filter(published=True, deleted_at__isnull=True).order_by(
"-publish_at"
)[:100]
def item_pubdate(self, item):
"""Returns the publish date as a timezone-aware datetime object"""
publish_date = item.publish_at
if publish_date:
datetime_obj = datetime.combine(publish_date, datetime.min.time())
aware_datetime_obj = make_aware(datetime_obj, timezone=timezone.utc)
return aware_datetime_obj
def item_description(self, item):
"""Return the Entry content in the description field.
If the Entry has an external URL (and no content), return a link to that URL
instead.
"""
if item.external_url and not item.content:
return (
f"External link to <a href='{ item.external_url }'>"
f"{ item.external_url }</a>."
)
content = item.content
# Convert URLs in the content to clickable links.
content = urlize(content)
# Convert newlines to <p> and <br> tags.
if content:
# Don't add empty paragraphs.
content = linebreaks(content)
return content
def item_title(self, item):
return item.title
class AtomNewsFeed(RSSNewsFeed):
"""The Atom feed version of the main Entry/News feed, which enables
the extra fields like `pubdate`
"""
feed_type = Atom1Feed