aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-12-13 14:06:05 +0100
committerGravatar Leon Sandøy <[email protected]>2020-12-13 14:06:05 +0100
commitbf06cc2c64b8c991070e6364c9ddc05b7da243f8 (patch)
tree87ba901aa26b56a71fc9a41e36c013f590d24ae8
parentFix incorrectly specified environment variable (diff)
Add some sanity to frontpage projects.
If no API data is available, the front page shouldn't crash and burn. This commit will ensure the front page will just render without the projects it can't get API data for instead of crashing the whole thing.
-rw-r--r--pydis_site/apps/home/views/home.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/pydis_site/apps/home/views/home.py b/pydis_site/apps/home/views/home.py
index c1c2055c..e9ed0df0 100644
--- a/pydis_site/apps/home/views/home.py
+++ b/pydis_site/apps/home/views/home.py
@@ -1,4 +1,5 @@
import datetime
+import logging
from typing import Dict, List
import requests
@@ -10,6 +11,8 @@ from django.views import View
from pydis_site.apps.home.models import RepositoryMetadata
+log = logging.getLogger(__name__)
+
class HomeView(View):
"""The main landing page for the website."""
@@ -67,22 +70,25 @@ class HomeView(View):
# Update or create all RepoData objects in self.repos
for repo_name, api_data in api_repositories.items():
- try:
- repo_data = RepositoryMetadata.objects.get(repo_name=repo_name)
- repo_data.description = api_data["description"]
- repo_data.language = api_data["language"]
- repo_data.forks = api_data["forks_count"]
- repo_data.stargazers = api_data["stargazers_count"]
- except RepositoryMetadata.DoesNotExist:
- repo_data = RepositoryMetadata(
- repo_name=api_data["full_name"],
- description=api_data["description"],
- forks=api_data["forks_count"],
- stargazers=api_data["stargazers_count"],
- language=api_data["language"],
- )
- repo_data.save()
- database_repositories.append(repo_data)
+ if api_data:
+ try:
+ repo_data = RepositoryMetadata.objects.get(repo_name=repo_name)
+ repo_data.description = api_data["description"]
+ repo_data.language = api_data["language"]
+ repo_data.forks = api_data["forks_count"]
+ repo_data.stargazers = api_data["stargazers_count"]
+ except RepositoryMetadata.DoesNotExist:
+ repo_data = RepositoryMetadata(
+ repo_name=api_data["full_name"],
+ description=api_data["description"],
+ forks=api_data["forks_count"],
+ stargazers=api_data["stargazers_count"],
+ language=api_data["language"],
+ )
+ repo_data.save()
+ database_repositories.append(repo_data)
+ else:
+ log.error(f"No API data is available for {repo_name}!")
return database_repositories
# Otherwise, if the data is fresher than 2 minutes old, we should just return it.