mirror of
https://github.com/boostorg/website-v2.git
synced 2026-01-19 04:42:17 +00:00
Pull in calendar data from the Google calendar
- Adds functions to retrieve raw events from the Google Calendar API, extract the data we need for those events, and order those events by month for display - Documents the new env vars - Adds new setting for the google calendar API url - Adds `/calendar/` to URLs, which displays the rendered google calendar **but didn't prettify it** - Adds events to homepage, using the existing template - Edits to the homepage template to show the events and make the paging arrows work
This commit is contained in:
committed by
Lacey Henschel
parent
20d06787a2
commit
73ea36b7a8
24
ak/views.py
24
ak/views.py
@@ -1,4 +1,5 @@
|
||||
import requests
|
||||
import structlog
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.shortcuts import render
|
||||
@@ -6,11 +7,15 @@ from django.views import View
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from config.settings import JDOODLE_API_CLIENT_ID, JDOODLE_API_CLIENT_SECRET
|
||||
from core.calendar import extract_calendar_events, events_by_month, get_calendar
|
||||
from libraries.models import Category, Library
|
||||
from news.models import Entry
|
||||
from versions.models import Version
|
||||
|
||||
|
||||
logger = structlog.get_logger()
|
||||
|
||||
|
||||
class HomepageView(TemplateView):
|
||||
"""
|
||||
Our default homepage for temp-site. We expect you to not use this view
|
||||
@@ -25,8 +30,27 @@ class HomepageView(TemplateView):
|
||||
latest_version = Version.objects.most_recent()
|
||||
context["latest_version"] = latest_version
|
||||
context["featured_library"] = self.get_featured_library(latest_version)
|
||||
context["events"] = self.get_events()
|
||||
if context["events"]:
|
||||
context["num_months"] = len(context["events"])
|
||||
else:
|
||||
context["num_months"] = 0
|
||||
return context
|
||||
|
||||
def get_events(self):
|
||||
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)
|
||||
return dict(sorted_events)
|
||||
|
||||
def get_featured_library(self, latest_version):
|
||||
library = Library.objects.filter(featured=True).first()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user