diff options
Diffstat (limited to 'pydis_site/apps/main')
-rw-r--r-- | pydis_site/apps/main/__init__.py | 0 | ||||
-rw-r--r-- | pydis_site/apps/main/admin.py | 3 | ||||
-rw-r--r-- | pydis_site/apps/main/apps.py | 5 | ||||
-rw-r--r-- | pydis_site/apps/main/migrations/__init__.py | 0 | ||||
-rw-r--r-- | pydis_site/apps/main/models.py | 3 | ||||
-rw-r--r-- | pydis_site/apps/main/templatetags/__init__.py | 0 | ||||
-rw-r--r-- | pydis_site/apps/main/templatetags/extra_filters.py | 8 | ||||
-rw-r--r-- | pydis_site/apps/main/tests.py | 9 | ||||
-rw-r--r-- | pydis_site/apps/main/urls.py | 11 | ||||
-rw-r--r-- | pydis_site/apps/main/views/__init__.py | 3 | ||||
-rw-r--r-- | pydis_site/apps/main/views/home.py | 47 |
11 files changed, 89 insertions, 0 deletions
diff --git a/pydis_site/apps/main/__init__.py b/pydis_site/apps/main/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/pydis_site/apps/main/__init__.py 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 --- /dev/null +++ b/pydis_site/apps/main/migrations/__init__.py 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 --- /dev/null +++ b/pydis_site/apps/main/templatetags/__init__.py 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() + + +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", {}) |