-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathviews.py
More file actions
231 lines (199 loc) · 8.47 KB
/
Copy pathviews.py
File metadata and controls
231 lines (199 loc) · 8.47 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
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
223
224
225
226
227
228
229
230
231
import structlog
from django.conf import settings
from django.core.cache import cache
from django.core.exceptions import PermissionDenied
from django.http import Http404, HttpResponse
from django.shortcuts import render
from django.urls import reverse
from django.views import View
from django.views.generic import TemplateView
from core.calendar import extract_calendar_events, events_by_month, get_calendar
from core.mixins import V3Mixin
from core.templatetags.custom_static import large_static
from libraries.constants import LATEST_RELEASE_URL_PATH_STR
from libraries.mixins import ContributorMixin
from news.models import Entry
from testimonials.models import Testimonial
from core.mock_data import SharedResources
logger = structlog.get_logger()
class HomepageView(V3Mixin, ContributorMixin, TemplateView):
"""
Define all the pieces that will be displayed on the home page
"""
template_name = "homepage.html"
v3_template_name = "v3/homepage.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["entries"] = Entry.objects.published().order_by("-publish_at")[:3]
context["events"] = self.get_events()
testimonials = (
Testimonial.objects.live()
.filter(pull_quote__gt="")
.order_by("-first_published_at")
)
context["testimonials"] = testimonials
context["num_testimonials"] = testimonials.count()
if context["events"]:
context["num_months"] = len(context["events"])
else:
context["num_months"] = 0
context["LATEST_RELEASE_URL_PATH_STR"] = LATEST_RELEASE_URL_PATH_STR
return context
def get_events(self):
"""Returns the events from the Boost Google Calendar."""
cached_events = cache.get(settings.EVENTS_CACHE_KEY)
if cached_events:
return cached_events
try:
raw_event_data = get_calendar()
except Exception:
logger.info("Error getting events")
return
if not raw_event_data:
return
events = extract_calendar_events(raw_event_data)
sorted_events = events_by_month(events)
cache.set(
settings.EVENTS_CACHE_KEY,
dict(sorted_events),
settings.EVENTS_CACHE_TIMEOUT,
)
return dict(sorted_events)
def get_v3_context_data(self, **kwargs):
ctx = super().get_v3_context_data(**kwargs)
ctx["install_card_pkg_managers"] = SharedResources.install_card_pkg_managers
ctx["install_card_system_install"] = SharedResources.install_card_system_install
demo_cards = [
{
"title": "Performant",
"description": "Optimized for production at any scale, Boost outperforms many standard benchmarks.",
"icon_name": "bullseye-arrow",
},
{
"title": "Peer-reviewed",
"description": "Well tested by members of the C++ standards committee.",
"icon_name": "get-help",
},
{
"title": "Portable",
"description": "Works across all platforms, compilers, and C++ standards.",
"icon_name": "link",
},
{
"title": "Innovative",
"description": "Over 40 Boost libraries have become part of the C++ standard over the past 25 years.",
"icon_name": "bullseye-arrow",
},
{
"title": "Community-powered",
"description": "Contributing to Boost builds credibility, sharpens skills, and advances careers.",
"icon_name": "human",
},
{
"title": "Known worldwide",
"description": "Used in countless projects, you've probably encountered Boost without realizing it.",
"icon_name": "link",
},
{
"title": "Free",
"description": "Open source now and always, thanks to the Boost Software License.",
"icon_name": "check",
},
{
"title": "Production-ready",
"description": "Battle-tested in critical systems across industries around the globe.",
"icon_name": "bullseye-arrow",
},
]
ctx["library_cards"] = demo_cards
ctx["why_boost_cards"] = demo_cards[:8]
ctx["calendar_card"] = {
"title": "Boost is released three times a year",
"text": "Each release has updates to existing libraries, and any new libraries that have passed the rigorous acceptance process.",
"primary_button_url": "www.example.com",
"primary_button_label": "View the Release Calendar",
"secondary_button_url": "www.example.com",
"secondary_button_label": "Secondary Button",
"image": large_static("img/v3/demo-page/calendar.png"),
}
ctx["info_card"] = {
"title": "How we got here",
"text": "Since 1998, Boost has been where C++ innovation happens. What started with three developers has grown into the foundation of modern C++ development.",
"primary_button_url": "www.example.com",
"primary_button_label": "Explore Our History",
}
tag_display = {"blogpost": "Blog"}
popular_entries = (
Entry.objects.ranked()
.filter(deleted_at__isnull=True, published=True)
.select_related("author")[:5]
)
ctx["posts_from_the_boost_community"] = {
"heading": "Posts from the Boost Community",
"primary_cta_label": "View all posts",
"primary_cta_url": reverse("news"),
"variant": "card",
"theme": "teal",
"items": [
{
"title": entry.title,
"url": entry.get_absolute_url(),
"date": entry.publish_at,
"category": (
tag_display.get(str(entry.tag).lower(), entry.tag.capitalize())
if entry.tag
else ""
),
"tag": "",
"author": entry.author.to_v3_profile_dict(),
}
for entry in popular_entries
],
}
ctx["join_developers_building_the_future_of_cpp"] = {
"items": SharedResources.demo_join_community_links[:5]
}
ctx["boost_community_data"] = {
"heading": "The Boost community",
"view_all_url": "#",
"view_all_label": "Explore the community",
"posts": SharedResources.demo_posts,
}
ctx["popular_terms"] = SharedResources.popular_terms
ctx["demo_events_with_links"] = SharedResources.demo_events_with_links[:4]
ctx["code_demo_hello"] = SharedResources.code_demo_hello
ctx["stats_in_numbers"] = {
"example_library_commits_bars": SharedResources.example_library_commits_bars
}
ctx["testimonial_data"] = {"testimonials": SharedResources.testimonials}
ctx["library_intro"] = SharedResources.library_intro
ctx["build_anything_with_boost"] = SharedResources.build_anything_with_boost
ctx["hero_legacy_image_url_light"] = SharedResources.hero_legacy_image_url_light
ctx["hero_legacy_image_url_dark"] = SharedResources.hero_legacy_image_url_dark
ctx["hero_image_url"] = SharedResources.hero_image_url
ctx["hero_image_url_light"] = SharedResources.hero_image_url_light
ctx["hero_image_url_dark"] = SharedResources.hero_image_url_dark
return ctx
class ForbiddenView(View):
"""
This view raises an exception to test our 403.html template
"""
def get(self, *args, **kwargs):
raise PermissionDenied("403 Forbidden")
class InternalServerErrorView(View):
"""
This view raises an exception to test our 500.html template
"""
def get(self, *args, **kwargs):
raise ValueError("500 Internal Server Error")
class NotFoundView(View):
"""
This view raises an exception to test our 404.html template
"""
def get(self, *args, **kwargs):
raise Http404("404 Not Found")
def custom_404_view(request, exception=None):
return render(request, "404.html", status=404)
class OKView(View):
def get(self, *args, **kwargs):
return HttpResponse("200 OK", status=200)