-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeeds.py
130 lines (101 loc) Β· 4.27 KB
/
feeds.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from django.contrib.syndication.views import Feed
from django.db.models.functions import Coalesce
from django.utils.feedgenerator import Atom1Feed
from requests import PreparedRequest
from taggit.models import Tag
from home.filtering import (
filter_on_abstract_page_properties,
filter_on_child_page_properties,
filter_page_with_any_of_tags,
)
from home.models.page_models import AbstractPage, Article, Page
class RSSFeed(Feed):
def get_object(self, request, type):
obj = {
"type": type
}
garden_status = request.GET.get('garden_status')
if garden_status:
obj["garden_status"] = garden_status
tags = request.GET.getlist('tags')
if tags:
obj['objects'] = filter_page_with_any_of_tags(tags)
obj["tags"] = tags
match type:
case "timeline":
if not tags:
obj["objects"] = (
Page.objects.live()
.filter(filter_on_abstract_page_properties(unlisted=False))
.order_by(Coalesce("go_live_at", "first_published_at")).reverse()
)
if garden_status:
obj['objects'] = obj['objects'].filter(filter_on_abstract_page_properties(garden_status=garden_status))
obj["link"] = "/timeline"
case "articles":
if tags:
obj['objects'] = obj['objects'].type(Article).filter(filter_on_child_page_properties(Article, article_type="article"))
if garden_status:
obj['objects'] = obj['objects'].filter(filter_on_child_page_properties(Article, garden_status=garden_status))
else:
obj["objects"] = (
Article.objects.live()
.filter(unlisted=False, article_type="article")
.order_by(Coalesce("go_live_at", "first_published_at")).reverse()
)
if garden_status:
obj['objects'] = obj['objects'].filter(garden_status=garden_status)
obj["link"] = "/articles"
case "notes":
if tags:
obj['objects'] = obj['objects'].type(Article).filter(filter_on_child_page_properties(Article, article_type="note"))
if garden_status:
obj['objects'] = obj['objects'].filter(filter_on_child_page_properties(Article, garden_status=garden_status))
else:
obj["objects"] = (
Article.objects.live()
.filter(unlisted=False, article_type="note")
.order_by(Coalesce("go_live_at", "first_published_at")).reverse()
)
if garden_status:
obj['objects'] = obj['objects'].filter(garden_status=garden_status)
obj["link"] = "/notes"
return obj
def title(self, obj):
return f"Luna Lux - {obj['type']}"
def description(self, obj):
return f"Additions to {obj['type']}."
def link(self, obj):
return obj["link"]
def items(self, obj):
return obj['objects']
def item_title(self, item):
return item.title
def item_description(self, item):
return item.search_description
def item_link(self, item):
utm_params = {
"utm_source": "rss",
"utm_medium": "feed"
}
req = PreparedRequest()
req.prepare_url(item.get_full_url(), utm_params)
print(req.url)
return req.url
def item_categories(self, item):
if isinstance(item.specific, AbstractPage):
categories = list(item.specific.tags.all())
if item.specific.garden_status != "n/a":
categories.append(item.specific.garden_status)
else:
categories = []
return categories
def item_author_name(self, item):
return item.owner.get_full_name()
def item_pubdate(self, item):
return item.effective_published_at
def item_updateddate(self, item):
return item.last_published_at
class AtomFeed(RSSFeed):
feed_type = Atom1Feed
subtitle = RSSFeed.description