-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
222 lines (160 loc) Β· 6.98 KB
/
views.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
from itertools import chain
from urllib.parse import unquote, urlparse
from django.db.models.functions import Coalesce, Trunc
from django.http import Http404, HttpRequest, QueryDict
from django.shortcuts import get_object_or_404, render
from django.utils import timezone
from taggit.models import Tag
from home.feeds import RSSFeed
from home.filtering import (
filter_on_abstract_page_properties,
filter_page_with_any_of_tags,
)
from home.models.helper_models import PageHit, PageTag
from home.models.page_models import AbstractPage, Article, HomePage, Page, Series
def hover_preview(request):
url = request.GET.get('url')
if not url:
raise Http404("No URL provided")
url = urlparse(unquote(url)).path
# find a bit more robust way of reversing wagtail page from url
page = get_object_or_404(Page, url_path__endswith=url).specific
return render(request, "components/hover_preview.html", context={"page":page})
def feed_preview(request):
url = request.GET.get('url')
if not url:
raise Http404("No URL provided")
url = urlparse(unquote(url))
content_type = url.path.split("/")[-1]
query_params = QueryDict(url.query)
r = HttpRequest()
r.GET = query_params
feed = RSSFeed().get_object(r, content_type)
pages = list(feed['objects'].specific())
num_pages = len(pages)
context = {
"pages":pages[:15],
"num_pages":num_pages,
"include_images":False,
"show_empty": True,
}
return render(request, "blocks/lines_list.html", context=context)
def garden_list(request):
garden_status = request.GET.get('garden_status')
# TODO Change to single queryset on page???
queryset = HomePage.objects.filter(live=True, unlisted=False).exclude(garden_status='na')
queryset2 = Article.objects.filter(live=True, unlisted=False).exclude(garden_status='na')
queryset3 = Series.objects.filter(live=True, unlisted=False).exclude(garden_status='na')
if garden_status:
queryset = queryset.filter(garden_status=garden_status)
queryset2 = queryset2.filter(garden_status=garden_status)
queryset3 = queryset3.filter(garden_status=garden_status)
def time(instance):
return instance.effective_published_at
queryies_combined = sorted(
chain(queryset, queryset2, queryset3),
key=time, reverse=True)
context = {"articles": queryies_combined, "tag": "Garden", 'hide_other_tags':True, "show_garden_status":True, "object_name": "Pages"}
context['description_text'] = "A collection of pages on various topics."
garden_filters = [{
'name': 'π± Seedling',
'title': 'For rough and early ideas',
'slug': 'seedling',
}, {
'name': 'πΏ Budding',
'title': 'For work that has been cleaned up and clarified',
'slug': 'budding',
}, {
'name': 'π³ Evergreen',
'title': "For work that's reasonably complete, but might still small receive updates",
'slug': 'evergreen',
}
]
context['garden_status'] = garden_status
context['garden_tags'] = garden_filters
# TODO: Don't use article_list template for garden view
# in general move away from exclusively using article_list template
return render(request, "article_list.html",
context=context)
def timeline(request):
# TODO Change to single queryset on page???
queryset = HomePage.objects.filter(live=True, unlisted=False).annotate(
year=Trunc(Coalesce("go_live_at", "first_published_at"), "year")
)
queryset2 = Article.objects.filter(live=True, unlisted=False).annotate(
year=Trunc(Coalesce("go_live_at", "first_published_at"), "year")
)
queryset3 = Series.objects.filter(live=True, unlisted=False).annotate(
year=Trunc(Coalesce("go_live_at", "first_published_at"), "year")
)
def time(instance):
return instance.effective_published_at
queryies_combined = sorted(
chain(queryset, queryset2, queryset3),
key=time, reverse=True)
tags = Article.tags.most_common()[:10]
context = {
"articles": queryies_combined,
"tag": "Timeline",
"hide_other_tags": True,
"object_name": "Pages",
"tags": tags,
"group_by_year": True,
}
context['description_text'] = "A chronological list of all pages."
return render(request, "article_list.html",
context=context)
def notes_list(request):
queryset = (
Article.objects.all()
.filter(live=True, article_type="note")
.filter(unlisted=False)
.order_by(Coalesce("go_live_at", "first_published_at")).reverse()
)
context = {"articles": queryset, "tag": "Notes", 'hide_other_tags':True, "object_name": "Notes"}
context['description_text'] = "A collection of notes on various topics."
return render(request, "article_list.html",
context=context)
def article_list(request):
queryset = Article.objects.all().filter(live=True, article_type="article").filter(unlisted=False)
queryset2 = Series.objects.live().filter(unlisted=False)
def time(instance):
try:
return instance.effective_published_at
except:
return instance.timestamp
queryies_combined = sorted(
chain(queryset, queryset2),
key=time, reverse=True)
tags = Article.tags.most_common().exclude(slug__in=['ai', 'physics'])[:10]
return render(request, "article_list.html",
context={"articles": queryies_combined, "tag": "all", 'tags':tags, "object_name": "Essays"})
def article_trending_list(request):
articles= Article.objects.first().get_trending_articles(n=15)
return render(request, "article_list.html",
context={"articles": articles, "tag": "Trending", "trending":True, "object_name": "Items"})
def tag_detail(request, tag):
tag = unquote(tag)
queryset = filter_page_with_any_of_tags(tags=[tag])
tags = Article.tags.most_common().exclude(slug=tag)[:10]
context = {"articles":queryset,
"object_name": "Items",
"tag":Tag.objects.get(slug=tag),
'tags':tags,
"hide_other_tags":True}
if request.GET.get('hide_other_tags'):
context["hide_other_tags"] = True
return render(request, "article_list.html",
context=context)
def project_list(request):
# TODO Change to single queryset on page???
queryset = HomePage.objects.filter(live=True, unlisted=False).filter(is_project=True)
queryset2 = Article.objects.filter(live=True, unlisted=False).filter(is_project=True)
queryset3 = Series.objects.filter(live=True, unlisted=False).filter(is_project=True)
def time(instance):
return instance.effective_published_at
queryies_combined = sorted(
chain(queryset, queryset2, queryset3),
key=time, reverse=True)
return render(request, "project_list.html",
context={"projects":queryies_combined})