From f29472a56f925127a077c4cadcc13fa852dc665b Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Sat, 13 Apr 2019 16:16:11 +0200 Subject: refactoring slightly to use a class-based view, changing home to main. Ready to write the API search stuff now. --- pydis_site/apps/home/__init__.py | 0 pydis_site/apps/home/admin.py | 3 -- pydis_site/apps/home/apps.py | 5 --- pydis_site/apps/home/migrations/__init__.py | 0 pydis_site/apps/home/models.py | 3 -- pydis_site/apps/home/templatetags/__init__.py | 0 pydis_site/apps/home/templatetags/extra_filters.py | 8 ---- pydis_site/apps/home/tests.py | 9 ----- pydis_site/apps/home/urls.py | 10 ----- pydis_site/apps/home/views.py | 3 -- pydis_site/apps/main/__init__.py | 0 pydis_site/apps/main/admin.py | 3 ++ pydis_site/apps/main/apps.py | 5 +++ pydis_site/apps/main/migrations/__init__.py | 0 pydis_site/apps/main/models.py | 3 ++ pydis_site/apps/main/templatetags/__init__.py | 0 pydis_site/apps/main/templatetags/extra_filters.py | 8 ++++ pydis_site/apps/main/tests.py | 9 +++++ pydis_site/apps/main/urls.py | 11 +++++ pydis_site/apps/main/views/__init__.py | 3 ++ pydis_site/apps/main/views/home.py | 47 ++++++++++++++++++++++ pydis_site/apps/wiki/__init__.py | 0 pydis_site/apps/wiki/admin.py | 3 -- pydis_site/apps/wiki/apps.py | 5 --- pydis_site/apps/wiki/migrations/__init__.py | 0 pydis_site/apps/wiki/models.py | 3 -- pydis_site/apps/wiki/tests.py | 3 -- pydis_site/apps/wiki/views.py | 3 -- 28 files changed, 89 insertions(+), 58 deletions(-) delete mode 100644 pydis_site/apps/home/__init__.py delete mode 100644 pydis_site/apps/home/admin.py delete mode 100644 pydis_site/apps/home/apps.py delete mode 100644 pydis_site/apps/home/migrations/__init__.py delete mode 100644 pydis_site/apps/home/models.py delete mode 100644 pydis_site/apps/home/templatetags/__init__.py delete mode 100644 pydis_site/apps/home/templatetags/extra_filters.py delete mode 100644 pydis_site/apps/home/tests.py delete mode 100644 pydis_site/apps/home/urls.py delete mode 100644 pydis_site/apps/home/views.py create mode 100644 pydis_site/apps/main/__init__.py create mode 100644 pydis_site/apps/main/admin.py create mode 100644 pydis_site/apps/main/apps.py create mode 100644 pydis_site/apps/main/migrations/__init__.py create mode 100644 pydis_site/apps/main/models.py create mode 100644 pydis_site/apps/main/templatetags/__init__.py create mode 100644 pydis_site/apps/main/templatetags/extra_filters.py create mode 100644 pydis_site/apps/main/tests.py create mode 100644 pydis_site/apps/main/urls.py create mode 100644 pydis_site/apps/main/views/__init__.py create mode 100644 pydis_site/apps/main/views/home.py delete mode 100644 pydis_site/apps/wiki/__init__.py delete mode 100644 pydis_site/apps/wiki/admin.py delete mode 100644 pydis_site/apps/wiki/apps.py delete mode 100644 pydis_site/apps/wiki/migrations/__init__.py delete mode 100644 pydis_site/apps/wiki/models.py delete mode 100644 pydis_site/apps/wiki/tests.py delete mode 100644 pydis_site/apps/wiki/views.py (limited to 'pydis_site/apps') diff --git a/pydis_site/apps/home/__init__.py b/pydis_site/apps/home/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/pydis_site/apps/home/admin.py b/pydis_site/apps/home/admin.py deleted file mode 100644 index 4185d360..00000000 --- a/pydis_site/apps/home/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.contrib import admin - -# Register your models here. diff --git a/pydis_site/apps/home/apps.py b/pydis_site/apps/home/apps.py deleted file mode 100644 index 90dc7137..00000000 --- a/pydis_site/apps/home/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class HomeConfig(AppConfig): - name = 'home' diff --git a/pydis_site/apps/home/migrations/__init__.py b/pydis_site/apps/home/migrations/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/pydis_site/apps/home/models.py b/pydis_site/apps/home/models.py deleted file mode 100644 index 0b4331b3..00000000 --- a/pydis_site/apps/home/models.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.db import models - -# Create your models here. diff --git a/pydis_site/apps/home/templatetags/__init__.py b/pydis_site/apps/home/templatetags/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/pydis_site/apps/home/templatetags/extra_filters.py b/pydis_site/apps/home/templatetags/extra_filters.py deleted file mode 100644 index edffe9ac..00000000 --- a/pydis_site/apps/home/templatetags/extra_filters.py +++ /dev/null @@ -1,8 +0,0 @@ -from django import template - -register = template.Library() - - -@register.filter -def starts_with(value: str, arg: str): - return value.startswith(arg) diff --git a/pydis_site/apps/home/tests.py b/pydis_site/apps/home/tests.py deleted file mode 100644 index 54fac6e8..00000000 --- a/pydis_site/apps/home/tests.py +++ /dev/null @@ -1,9 +0,0 @@ -from django.test import TestCase -from django_hosts.resolvers import reverse - - -class TestIndexReturns200(TestCase): - def test_index_returns_200(self): - url = reverse('index') - resp = self.client.get(url) - self.assertEqual(resp.status_code, 200) diff --git a/pydis_site/apps/home/urls.py b/pydis_site/apps/home/urls.py deleted file mode 100644 index 56525af8..00000000 --- a/pydis_site/apps/home/urls.py +++ /dev/null @@ -1,10 +0,0 @@ -from django.contrib import admin -from django.urls import path -from django.views.generic import TemplateView - - -app_name = 'home' -urlpatterns = [ - path('', TemplateView.as_view(template_name='home/index.html'), name='home.index'), - path('admin/', admin.site.urls) -] diff --git a/pydis_site/apps/home/views.py b/pydis_site/apps/home/views.py deleted file mode 100644 index fd0e0449..00000000 --- a/pydis_site/apps/home/views.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.shortcuts import render - -# Create your views here. diff --git a/pydis_site/apps/main/__init__.py b/pydis_site/apps/main/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pydis_site/apps/main/admin.py b/pydis_site/apps/main/admin.py new file mode 100644 index 00000000..4185d360 --- /dev/null +++ b/pydis_site/apps/main/admin.py @@ -0,0 +1,3 @@ +# from django.contrib import admin + +# Register your models here. diff --git a/pydis_site/apps/main/apps.py b/pydis_site/apps/main/apps.py new file mode 100644 index 00000000..90dc7137 --- /dev/null +++ b/pydis_site/apps/main/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class HomeConfig(AppConfig): + name = 'home' diff --git a/pydis_site/apps/main/migrations/__init__.py b/pydis_site/apps/main/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pydis_site/apps/main/models.py b/pydis_site/apps/main/models.py new file mode 100644 index 00000000..0b4331b3 --- /dev/null +++ b/pydis_site/apps/main/models.py @@ -0,0 +1,3 @@ +# from django.db import models + +# Create your models here. diff --git a/pydis_site/apps/main/templatetags/__init__.py b/pydis_site/apps/main/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pydis_site/apps/main/templatetags/extra_filters.py b/pydis_site/apps/main/templatetags/extra_filters.py new file mode 100644 index 00000000..edffe9ac --- /dev/null +++ b/pydis_site/apps/main/templatetags/extra_filters.py @@ -0,0 +1,8 @@ +from django import template + +register = template.Library() + + +@register.filter +def starts_with(value: str, arg: str): + return value.startswith(arg) diff --git a/pydis_site/apps/main/tests.py b/pydis_site/apps/main/tests.py new file mode 100644 index 00000000..54fac6e8 --- /dev/null +++ b/pydis_site/apps/main/tests.py @@ -0,0 +1,9 @@ +from django.test import TestCase +from django_hosts.resolvers import reverse + + +class TestIndexReturns200(TestCase): + def test_index_returns_200(self): + url = reverse('index') + resp = self.client.get(url) + self.assertEqual(resp.status_code, 200) diff --git a/pydis_site/apps/main/urls.py b/pydis_site/apps/main/urls.py new file mode 100644 index 00000000..11142040 --- /dev/null +++ b/pydis_site/apps/main/urls.py @@ -0,0 +1,11 @@ +from django.contrib import admin +from django.urls import path + +from .views import Home + + +app_name = 'home' +urlpatterns = [ + path('', Home.as_view(), name='home.index'), + path('admin/', admin.site.urls) +] diff --git a/pydis_site/apps/main/views/__init__.py b/pydis_site/apps/main/views/__init__.py new file mode 100644 index 00000000..ab52894b --- /dev/null +++ b/pydis_site/apps/main/views/__init__.py @@ -0,0 +1,3 @@ +from .home import Home + +__all__ = ["Home"] diff --git a/pydis_site/apps/main/views/home.py b/pydis_site/apps/main/views/home.py new file mode 100644 index 00000000..8f45b912 --- /dev/null +++ b/pydis_site/apps/main/views/home.py @@ -0,0 +1,47 @@ +import requests +from django.shortcuts import render +from django.views import View + + + +class Home(View): + + projects = [ + "site", + "bot", + "snekbox", + "seasonalbot", + "django-simple-bulma", + "django-crispy-bulma", + ] + + def _get_repo_data(self): + """ + This will get language, stars and forks for the projects listed in Home.projects. + + Returns a dictionary with the data, in a template-friendly manner. The rate limit for + this particular endpoint is 30 requests per minute. This should be plenty for now, + but if we ever run into rate limiting issues, we should implement some form of caching + for this data. + """ + + # Gotta authenticate, or we get terrible rate limits. + + # We need to query the Search API https://developer.github.com/v3/search/, using a single + # query to query for all of the projects at the same time, and making sure we cache that data + # and make the request no more often than once per minute or something reasonable + # like that. + + endpoint = "https://api.github.com/search/repositories?q=" + "repo+name+separated+by+pluses" + + # And finally + + + + + + + def get(self, request): + + # Call the GitHub API and ask it for some data + return render(request, "home/index.html", {}) diff --git a/pydis_site/apps/wiki/__init__.py b/pydis_site/apps/wiki/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/pydis_site/apps/wiki/admin.py b/pydis_site/apps/wiki/admin.py deleted file mode 100644 index 4185d360..00000000 --- a/pydis_site/apps/wiki/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.contrib import admin - -# Register your models here. diff --git a/pydis_site/apps/wiki/apps.py b/pydis_site/apps/wiki/apps.py deleted file mode 100644 index fce4708e..00000000 --- a/pydis_site/apps/wiki/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class WikiConfig(AppConfig): - name = 'wiki' diff --git a/pydis_site/apps/wiki/migrations/__init__.py b/pydis_site/apps/wiki/migrations/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/pydis_site/apps/wiki/models.py b/pydis_site/apps/wiki/models.py deleted file mode 100644 index 0b4331b3..00000000 --- a/pydis_site/apps/wiki/models.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.db import models - -# Create your models here. diff --git a/pydis_site/apps/wiki/tests.py b/pydis_site/apps/wiki/tests.py deleted file mode 100644 index a79ca8be..00000000 --- a/pydis_site/apps/wiki/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.test import TestCase - -# Create your tests here. diff --git a/pydis_site/apps/wiki/views.py b/pydis_site/apps/wiki/views.py deleted file mode 100644 index fd0e0449..00000000 --- a/pydis_site/apps/wiki/views.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.shortcuts import render - -# Create your views here. -- cgit v1.2.3 From 1583b86a6215c879a667f304512d4708c77e9f82 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Tue, 16 Apr 2019 17:58:29 +0200 Subject: makemigrations pipeline created, RepoData model created, and a really naive implementation of the API stuff which makes 6 requests and takes forever to load. I've found a better approach so I'm gonna switch to that next. --- Pipfile | 4 ++ docker-compose.yml | 4 +- docker/pysite.dockerapp | 2 + pydis_site/apps/main/models/__init__.py | 3 + pydis_site/apps/main/models/repo_data.py | 33 +++++++++++ pydis_site/apps/main/views/home.py | 94 ++++++++++++++++++++------------ 6 files changed, 103 insertions(+), 37 deletions(-) create mode 100644 pydis_site/apps/main/models/__init__.py create mode 100644 pydis_site/apps/main/models/repo_data.py (limited to 'pydis_site/apps') diff --git a/Pipfile b/Pipfile index 1e106f07..62d475e4 100644 --- a/Pipfile +++ b/Pipfile @@ -30,3 +30,7 @@ requests = "*" [requires] python_version = "3.7" + +[scripts] +makemigrations = "python manage.py makemigrations" +django_shell = "python manage.py shell" diff --git a/docker-compose.yml b/docker-compose.yml index 04ec51de..0c504c40 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,8 @@ version: "3.6" services: postgres: image: postgres:11-alpine + ports: + - "127.0.0.1:7777:5432" environment: POSTGRES_DB: pysite POSTGRES_PASSWORD: supersecretpassword @@ -30,7 +32,7 @@ services: - .:/app:ro - staticfiles:/var/www/static environment: - DATABASE_URL: postgres://pysite:supersecretpassword@postgres/pysite + DATABASE_URL: postgres://pysite:supersecretpassword@postgres:5432/pysite DEBUG: "true" SECRET_KEY: suitable-for-development-only STATIC_ROOT: /var/www/static diff --git a/docker/pysite.dockerapp b/docker/pysite.dockerapp index dc472b2e..2426008e 100644 --- a/docker/pysite.dockerapp +++ b/docker/pysite.dockerapp @@ -25,6 +25,8 @@ services: postgres: image: postgres:11-alpine + ports: + - "127.0.0.1:5432:5432" environment: POSTGRES_DB: "${pg_db}" POSTGRES_USER: "${pg_user}" diff --git a/pydis_site/apps/main/models/__init__.py b/pydis_site/apps/main/models/__init__.py new file mode 100644 index 00000000..7a2cbb0b --- /dev/null +++ b/pydis_site/apps/main/models/__init__.py @@ -0,0 +1,3 @@ +from .repo_data import RepoData + +__all__ = ["RepoData"] diff --git a/pydis_site/apps/main/models/repo_data.py b/pydis_site/apps/main/models/repo_data.py new file mode 100644 index 00000000..40540410 --- /dev/null +++ b/pydis_site/apps/main/models/repo_data.py @@ -0,0 +1,33 @@ +from django.db import models +from django.utils import timezone + + +class RepoData(models.Model): + """Information about one of our repos fetched from the GitHub API.""" + + last_updated = models.DateTimeField( + default=timezone.now, + help_text="The date and time this data was last fetched." + ) + repo_name = models.CharField( + primary_key=True, + max_length=40, + help_text="The full name of the repo, e.g. python-discord/site" + ) + description = models.CharField( + max_length=400, + help_text="The description of the repo." + ) + forks = models.IntegerField( + help_text="The number of forks of this repo" + ) + stargazers = models.IntegerField( + help_text="The number of stargazers for this repo" + ) + language = models.CharField( + max_length=20, + help_text="The primary programming language used for this repo." + ) + + def __str__(self): + return self.repo_name diff --git a/pydis_site/apps/main/views/home.py b/pydis_site/apps/main/views/home.py index 8f45b912..883177bb 100644 --- a/pydis_site/apps/main/views/home.py +++ b/pydis_site/apps/main/views/home.py @@ -1,47 +1,69 @@ import requests + from django.shortcuts import render +from django.utils import timezone from django.views import View +from pydis_site.apps.main.models import RepoData +GITHUB_API = "https://api.github.com/repos" +REPOS = [ + "python-discord/site", + "python-discord/bot", + "python-discord/snekbox", + "python-discord/seasonalbot", + "python-discord/django-simple-bulma", + "python-discord/django-crispy-bulma", +] - -class Home(View): - - projects = [ - "site", - "bot", - "snekbox", - "seasonalbot", - "django-simple-bulma", - "django-crispy-bulma", - ] - - def _get_repo_data(self): - """ - This will get language, stars and forks for the projects listed in Home.projects. - - Returns a dictionary with the data, in a template-friendly manner. The rate limit for - this particular endpoint is 30 requests per minute. This should be plenty for now, - but if we ever run into rate limiting issues, we should implement some form of caching - for this data. - """ - - # Gotta authenticate, or we get terrible rate limits. - - # We need to query the Search API https://developer.github.com/v3/search/, using a single - # query to query for all of the projects at the same time, and making sure we cache that data - # and make the request no more often than once per minute or something reasonable - # like that. - - endpoint = "https://api.github.com/search/repositories?q=" + "repo+name+separated+by+pluses" - - # And finally - - - +# https://api.github.com/users/python-discord/repos gets all the data in one query. +class Home(View): + def _get_repo_data(self, repo_name): + """This will get language, stars and forks for the requested GitHub repo.""" + + # Try to get the data from the cache + try: + repo_data = RepoData.objects.get(repo_name=repo_name) + + # If the data is older than 2 minutes, we should refresh it + if (timezone.now() - repo_data.last_updated).seconds > 120: + + # Fetch the data from the GitHub API + api_data = requests.get(f"{GITHUB_API}/{repo_name}") + api_data = api_data.json() + + # Update the current object, and save it. + 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"] + repo_data.save() + return repo_data + + # Otherwise, if the data is fresher than 2 minutes old, we should just return it. + else: + return repo_data + + # If this is raised, the data isn't there at all, so we'll need to create it. + except RepoData.DoesNotExist: + api_data = requests.get(f"{GITHUB_API}/{repo_name}") + api_data = api_data.json() + repo_data = RepoData( + description=api_data["description"], + forks=api_data["forks_count"], + stargazers=api_data["stargazers_count"], + language=api_data["language"], + ) + repo_data.save() + return repo_data def get(self, request): + # Collect the repo data + repo_data = [] + for repo in REPOS: + repo_data.append(self._get_repo_data(repo)) + # Call the GitHub API and ask it for some data - return render(request, "home/index.html", {}) + return render(request, "home/index.html", {"repo_data": repo_data}) -- cgit v1.2.3 From cf1fc2870326c431d0c4dc3fe46f2ae41c2fd5aa Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Wed, 17 Apr 2019 23:57:14 +0200 Subject: The GitHub API stuff is done now, including data caching. Just a couple of minor bugfixes left before this is PR-ready. --- pydis_site/apps/main/models.py | 3 - pydis_site/apps/main/views/home.py | 119 ++++++++++++++++++++++------------ pydis_site/settings.py | 10 +++ pydis_site/static/css/home/index.css | 11 ++++ pydis_site/templates/base/navbar.html | 24 +++---- pydis_site/templates/home/index.html | 105 +++++------------------------- 6 files changed, 129 insertions(+), 143 deletions(-) delete mode 100644 pydis_site/apps/main/models.py (limited to 'pydis_site/apps') diff --git a/pydis_site/apps/main/models.py b/pydis_site/apps/main/models.py deleted file mode 100644 index 0b4331b3..00000000 --- a/pydis_site/apps/main/models.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.db import models - -# Create your models here. diff --git a/pydis_site/apps/main/views/home.py b/pydis_site/apps/main/views/home.py index 883177bb..f3f9d726 100644 --- a/pydis_site/apps/main/views/home.py +++ b/pydis_site/apps/main/views/home.py @@ -3,67 +3,104 @@ import requests from django.shortcuts import render from django.utils import timezone from django.views import View +from django.conf import settings from pydis_site.apps.main.models import RepoData -GITHUB_API = "https://api.github.com/repos" -REPOS = [ - "python-discord/site", - "python-discord/bot", - "python-discord/snekbox", - "python-discord/seasonalbot", - "python-discord/django-simple-bulma", - "python-discord/django-crispy-bulma", -] - -# https://api.github.com/users/python-discord/repos gets all the data in one query. +GITHUB_API = "https://api.github.com/users/python-discord/repos" class Home(View): - def _get_repo_data(self, repo_name): - """This will get language, stars and forks for the requested GitHub repo.""" - # Try to get the data from the cache + def _get_api_data(self): + """Call the GitHub API and get information about our repos.""" + repo_dict = {repo_name: {} for repo_name in settings.HOMEPAGE_REPOS} + + # Fetch the data from the GitHub API + api_data = requests.get(GITHUB_API) + api_data = api_data.json() + + # Process the API data into our dict + print(f"repo_dict = {repo_dict}") + for repo in api_data: + full_name = repo["full_name"] + + if full_name in settings.HOMEPAGE_REPOS: + repo_dict[full_name] = { + "full_name": repo["full_name"], + "description": repo["description"], + "language": repo["language"], + "forks_count": repo["forks_count"], + "stargazers_count": repo["stargazers_count"], + } + print(f"repo_dict after processing = {repo_dict}") + return repo_dict + + def _get_repo_data(self): + """Build a list of RepoData objects that we can use to populate the front page.""" + + # Try to get site data from the cache try: - repo_data = RepoData.objects.get(repo_name=repo_name) + repo_data = RepoData.objects.get(repo_name="python-discord/site") - # If the data is older than 2 minutes, we should refresh it + # If the data is older than 2 minutes, we should refresh it. THIS PROBABLY ALWAYS FAILS? if (timezone.now() - repo_data.last_updated).seconds > 120: - # Fetch the data from the GitHub API - api_data = requests.get(f"{GITHUB_API}/{repo_name}") - api_data = api_data.json() + diff = (timezone.now() - repo_data.last_updated).seconds + print(f"okay baby, it's old! the seconds difference comes to: {diff}") - # Update the current object, and save it. - 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"] - repo_data.save() - return repo_data + # Get new data from API + api_data_container = self._get_api_data() + repo_data_container = [] + + # Update or create all RepoData objects in settings.HOMEPAGE_REPOS + for repo_name, api_data in api_data_container.items(): + try: + repo_data = RepoData.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 RepoData.DoesNotExist: + repo_data = RepoData( + 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() + repo_data_container.append(repo_data) + return repo_data_container # Otherwise, if the data is fresher than 2 minutes old, we should just return it. else: - return repo_data + return list(RepoData.objects.all()) - # If this is raised, the data isn't there at all, so we'll need to create it. + # If this is raised, the database has no repodata at all, we will create them all. except RepoData.DoesNotExist: - api_data = requests.get(f"{GITHUB_API}/{repo_name}") - api_data = api_data.json() - repo_data = RepoData( - description=api_data["description"], - forks=api_data["forks_count"], - stargazers=api_data["stargazers_count"], - language=api_data["language"], - ) - repo_data.save() - return repo_data + + # Get new data from API + api_data_container = self._get_api_data() + repo_data_container = [] + + # Create all the repodata records in the database. + for repo_name, api_data in api_data_container.items(): + repo_data = RepoData( + 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() + repo_data_container.append(repo_data) + + return repo_data_container def get(self, request): # Collect the repo data - repo_data = [] - for repo in REPOS: - repo_data.append(self._get_repo_data(repo)) + repo_data = self._get_repo_data() # Call the GitHub API and ask it for some data return render(request, "home/index.html", {"repo_data": repo_data}) diff --git a/pydis_site/settings.py b/pydis_site/settings.py index 4a5b0523..eb21de10 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -258,3 +258,13 @@ BULMA_SETTINGS = { "footer-padding": "1rem 1.5rem 1rem", } } + +# Which of our GitHub repos should be displayed on the front page, and in which order? +HOMEPAGE_REPOS = [ + "python-discord/site", + "python-discord/bot", + "python-discord/snekbox", + "python-discord/seasonalbot", + "python-discord/django-simple-bulma", + "python-discord/django-crispy-bulma", +] diff --git a/pydis_site/static/css/home/index.css b/pydis_site/static/css/home/index.css index 2e201441..d1d1c01e 100644 --- a/pydis_site/static/css/home/index.css +++ b/pydis_site/static/css/home/index.css @@ -53,6 +53,17 @@ margin: 8px auto auto auto; } +div.card.github-card { + box-shadow: none; + border: #d1d5da 1px solid; + border-radius: 3px; +} + +div.repo-headline { + font-size: 1.25rem; + margin-bottom: 8px; +} + span.repo-language-dot { border-radius: 50%; height: 12px; diff --git a/pydis_site/templates/base/navbar.html b/pydis_site/templates/base/navbar.html index f9f576df..842d29d5 100644 --- a/pydis_site/templates/base/navbar.html +++ b/pydis_site/templates/base/navbar.html @@ -19,10 +19,10 @@ {# Content on the right side of the navbar #}