From c998d475440cf4819bad7ebc3ed19f31ce82baf4 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Tue, 8 Jun 2021 00:26:40 +0200 Subject: Move subdomains to query paths. In more detail: - Use Django URL namespaces (e.g. `api:bot:infractions`) instead of `django_hosts` host argument. - Update the hosts file setup documentation to remove subdomain entries. - Update the hosts file setup documentation to mention that the entry of `pythondiscord.local` is not required and mainly for convenience. - Rename the `APISubdomainTestCase` to the more fitting `AuthenticatedAPITestCase`, as authentication is all that is left that the class is doing. - Drop dependency to `django_hosts`. --- pydis_site/settings.py | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'pydis_site/settings.py') diff --git a/pydis_site/settings.py b/pydis_site/settings.py index 7df7ad85..f7c4401d 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -52,13 +52,7 @@ elif 'CI' in os.environ: else: ALLOWED_HOSTS = env.list( 'ALLOWED_HOSTS', - default=[ - 'pythondiscord.com', - 'admin.pythondiscord.com', - 'api.pythondiscord.com', - 'staff.pythondiscord.com', - 'pydis-api.default.svc.cluster.local', - ] + default=['pythondiscord.com'], ) SECRET_KEY = env('SECRET_KEY') @@ -80,7 +74,6 @@ INSTALLED_APPS = [ 'django.contrib.sites', 'django.contrib.staticfiles', - 'django_hosts', 'django_filters', 'django_simple_bulma', 'rest_framework', @@ -88,8 +81,6 @@ INSTALLED_APPS = [ ] MIDDLEWARE = [ - 'django_hosts.middleware.HostsRequestMiddleware', - 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -98,8 +89,6 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - - 'django_hosts.middleware.HostsResponseMiddleware', ] ROOT_URLCONF = 'pydis_site.urls' @@ -109,10 +98,6 @@ TEMPLATES = [ 'DIRS': [os.path.join(BASE_DIR, 'pydis_site', 'templates')], 'APP_DIRS': True, 'OPTIONS': { - 'builtins': [ - 'django_hosts.templatetags.hosts_override', - ], - 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', @@ -174,11 +159,6 @@ STATICFILES_FINDERS = [ 'django_simple_bulma.finders.SimpleBulmaFinder', ] -# django-hosts -# https://django-hosts.readthedocs.io/en/latest/ -ROOT_HOSTCONF = 'pydis_site.hosts' -DEFAULT_HOST = 'home' - if DEBUG: PARENT_HOST = env('PARENT_HOST', default='pythondiscord.local:8000') -- cgit v1.2.3 From 26be9bebfdb151a7e6d3e855c8d2a509ae1d4d38 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Wed, 6 Oct 2021 00:41:23 +0400 Subject: Switches HTTP Links To HTTPS Switches the protocol for external sites where possible. Some sites don't have secure versions, and were skipped. Signed-off-by: Hassan Abouelela --- pydis_site/apps/api/urls.py | 2 +- pydis_site/apps/content/resources/frequently-asked-questions.md | 2 +- .../contributing/contributing-guidelines/supplemental-information.md | 2 +- .../guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md | 2 +- pydis_site/apps/resources/resources/communities/panda3d.yaml | 2 +- pydis_site/apps/resources/resources/reading/books/byte_of_python.yaml | 2 +- .../apps/resources/resources/reading/books/flask_web_development.yaml | 2 +- pydis_site/apps/resources/resources/reading/books/python_cookbook.yaml | 2 +- .../apps/resources/resources/reading/tutorials/simple_guide_to_git.yaml | 2 +- pydis_site/apps/resources/resources/videos/microsoft.yaml | 2 +- pydis_site/settings.py | 2 +- pydis_site/templates/base/navbar.html | 2 +- pydis_site/templates/events/pages/code-jams/8/frameworks.html | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) (limited to 'pydis_site/settings.py') diff --git a/pydis_site/apps/api/urls.py b/pydis_site/apps/api/urls.py index 2e1ef0b4..b0ab545b 100644 --- a/pydis_site/apps/api/urls.py +++ b/pydis_site/apps/api/urls.py @@ -16,7 +16,7 @@ from .viewsets import ( UserViewSet ) -# http://www.django-rest-framework.org/api-guide/routers/#defaultrouter +# https://www.django-rest-framework.org/api-guide/routers/#defaultrouter bot_router = DefaultRouter(trailing_slash=False) bot_router.register( 'filter-lists', diff --git a/pydis_site/apps/content/resources/frequently-asked-questions.md b/pydis_site/apps/content/resources/frequently-asked-questions.md index 212ea5f8..a9a092fe 100644 --- a/pydis_site/apps/content/resources/frequently-asked-questions.md +++ b/pydis_site/apps/content/resources/frequently-asked-questions.md @@ -89,7 +89,7 @@ It's also to ease the burden on our moderators, otherwise they would have to dow Even though Discord does support previewing of files like `.txt` and `.py`, that support is only available on Desktop, not mobile. Additionally, we prefer people to use hastebin as it encourages them to only copy over the relevant code snippets instead of their whole code; this makes helping much easier for all involved. -If you want to share code please use our hosted hastebin, [paste.pythondiscord.com](http://paste.pythondiscord.com). +If you want to share code please use our hosted hastebin, [paste.pythondiscord.com](https://paste.pythondiscord.com). #### **Q: Why is this permission not allowed in that channel?** diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/contributing-guidelines/supplemental-information.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/contributing-guidelines/supplemental-information.md index 70d47563..e64e4fc6 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/contributing-guidelines/supplemental-information.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/contributing-guidelines/supplemental-information.md @@ -90,7 +90,7 @@ Our projects currently defines logging levels as follows, from lowest to highest - **ERROR:** These events can cause a failure in a specific part of the application and require urgent attention. - **CRITICAL:** These events can cause the whole application to fail and require immediate intervention. -Any logging above the **INFO** level will trigger a [Sentry](http://sentry.io) issue and alert the Core Developer team. +Any logging above the **INFO** level will trigger a [Sentry](https://sentry.io) issue and alert the Core Developer team. ## Draft Pull Requests diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md index 2a7ef0d6..eba737ad 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md @@ -43,7 +43,7 @@ If you will be working with an external service, you might have to set one of th | -------- | -------- | | `GITHUB_TOKEN` | Personal access token for GitHub, raises rate limits from 60 to 5000 requests per hour. | | `GIPHY_TOKEN` | Required for API access. [Docs](https://developers.giphy.com/docs/api) | -| `OMDB_API_KEY` | Required for API access. [Docs](http://www.omdbapi.com/) | +| `OMDB_API_KEY` | Required for API access. [Docs](https://www.omdbapi.com/) | | `REDDIT_CLIENT_ID` | OAuth2 client ID for authenticating with the [reddit API](https://github.com/reddit-archive/reddit/wiki/OAuth2). | | `REDDIT_SECRET` | OAuth2 secret for authenticating with the reddit API. *Leave empty if you're not using the reddit API.* | | `REDDIT_WEBHOOK` | Webhook ID for Reddit channel | diff --git a/pydis_site/apps/resources/resources/communities/panda3d.yaml b/pydis_site/apps/resources/resources/communities/panda3d.yaml index 4235793d..47797882 100644 --- a/pydis_site/apps/resources/resources/communities/panda3d.yaml +++ b/pydis_site/apps/resources/resources/communities/panda3d.yaml @@ -1,6 +1,6 @@ description: Panda3D is a Python-focused 3-D framework for rapid development of games, visualizations, and simulations, written in C++ with an emphasis on performance and flexibility. -title_image: http://www.panda3d.org/wp-content/uploads/2019/01/panda3d_logo.png +title_image: https://www.panda3d.org/wp-content/uploads/2019/01/panda3d_logo.png title_url: https://discord.gg/9XsucTT position: 9 urls: diff --git a/pydis_site/apps/resources/resources/reading/books/byte_of_python.yaml b/pydis_site/apps/resources/resources/reading/books/byte_of_python.yaml index 1f9642ad..2530c1a4 100644 --- a/pydis_site/apps/resources/resources/reading/books/byte_of_python.yaml +++ b/pydis_site/apps/resources/resources/reading/books/byte_of_python.yaml @@ -8,7 +8,7 @@ urls: url: https://python.swaroopch.com/ color: teal - icon: regular/book - url: http://www.lulu.com/shop/swaroop-c-h/a-byte-of-python/paperback/product-21142968.html + url: https://www.lulu.com/shop/swaroop-c-h/a-byte-of-python/paperback/product-21142968.html color: black - icon: branding/amazon url: https://www.amazon.com/Byte-Python-Swaroop-C-H-ebook/dp/B00FJ7S2JU/ diff --git a/pydis_site/apps/resources/resources/reading/books/flask_web_development.yaml b/pydis_site/apps/resources/resources/reading/books/flask_web_development.yaml index cc83a331..d191f02d 100644 --- a/pydis_site/apps/resources/resources/reading/books/flask_web_development.yaml +++ b/pydis_site/apps/resources/resources/reading/books/flask_web_development.yaml @@ -4,7 +4,7 @@ name: Flask Web Development position: 6 urls: - icon: regular/link - url: http://shop.oreilly.com/product/0636920031116.do + url: https://shop.oreilly.com/product/0636920031116.do color: teal - icon: branding/amazon url: https://www.amazon.com/Flask-Web-Development-Developing-Applications/dp/1449372627 diff --git a/pydis_site/apps/resources/resources/reading/books/python_cookbook.yaml b/pydis_site/apps/resources/resources/reading/books/python_cookbook.yaml index 032f8c64..c939ab9e 100644 --- a/pydis_site/apps/resources/resources/reading/books/python_cookbook.yaml +++ b/pydis_site/apps/resources/resources/reading/books/python_cookbook.yaml @@ -4,7 +4,7 @@ name: Python Cookbook position: 8 urls: - icon: regular/link - url: http://shop.oreilly.com/product/0636920027072.do + url: https://shop.oreilly.com/product/0636920027072.do color: teal - icon: branding/amazon url: https://www.amazon.com/Python-Cookbook-Third-David-Beazley/dp/1449340377 diff --git a/pydis_site/apps/resources/resources/reading/tutorials/simple_guide_to_git.yaml b/pydis_site/apps/resources/resources/reading/tutorials/simple_guide_to_git.yaml index a505715d..9d151bf9 100644 --- a/pydis_site/apps/resources/resources/reading/tutorials/simple_guide_to_git.yaml +++ b/pydis_site/apps/resources/resources/reading/tutorials/simple_guide_to_git.yaml @@ -1,6 +1,6 @@ description: A simple, no-nonsense guide to the basics of using Git. name: A Simple Guide to Git -title_url: http://rogerdudler.github.io/git-guide/ +title_url: https://rogerdudler.github.io/git-guide/ title_icon: branding/github title_icon_color: black position: 4 diff --git a/pydis_site/apps/resources/resources/videos/microsoft.yaml b/pydis_site/apps/resources/resources/videos/microsoft.yaml index 720ee202..3ceaa1a2 100644 --- a/pydis_site/apps/resources/resources/videos/microsoft.yaml +++ b/pydis_site/apps/resources/resources/videos/microsoft.yaml @@ -7,7 +7,7 @@ description: A trove of tutorials & guides for developers from Microsoft's Devel Microsoft's Python Development Team also runs a Discord Server for discussions of Python in the Microsoft ecosystem, including Visual Studio Code and Azure. -title_image: http://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE2qVsJ?ver=3f74 +title_image: https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE2qVsJ?ver=3f74 position: 4 urls: - icon: branding/youtube diff --git a/pydis_site/settings.py b/pydis_site/settings.py index d2cd8698..8d092ac9 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -201,7 +201,7 @@ else: PARENT_HOST = env('PARENT_HOST', default='pythondiscord.com') # Django REST framework -# http://www.django-rest-framework.org +# https://www.django-rest-framework.org REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.TokenAuthentication', diff --git a/pydis_site/templates/base/navbar.html b/pydis_site/templates/base/navbar.html index d7cb49b2..ed04995c 100644 --- a/pydis_site/templates/base/navbar.html +++ b/pydis_site/templates/base/navbar.html @@ -44,7 +44,7 @@ {# Patreon #} - +  Patreon diff --git a/pydis_site/templates/events/pages/code-jams/8/frameworks.html b/pydis_site/templates/events/pages/code-jams/8/frameworks.html index 34ac4f0a..1c02e38a 100644 --- a/pydis_site/templates/events/pages/code-jams/8/frameworks.html +++ b/pydis_site/templates/events/pages/code-jams/8/frameworks.html @@ -19,7 +19,7 @@
    -
  • Documentation Link
  • +
  • Documentation Link
  • Supports: Linux, Mac, other unix-like OS
  • Somewhat in-depth tutorial
  • Uses widgets in a fairly straight forward design
  • -- cgit v1.2.3 From 8f596f3b5fd44a502efccc021ab4c50908da3d67 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Wed, 6 Oct 2021 00:18:37 +0100 Subject: Add www.pythondiscord.com to ALLOWED_HOSTS (#601) --- pydis_site/settings.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pydis_site/settings.py') diff --git a/pydis_site/settings.py b/pydis_site/settings.py index d2cd8698..656676da 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -55,6 +55,7 @@ else: ALLOWED_HOSTS = env.list( 'ALLOWED_HOSTS', default=[ + 'www.pythondiscord.com', 'pythondiscord.com', 'admin.pythondiscord.com', 'api.pythondiscord.com', -- cgit v1.2.3 From 6a129ca9272a4b85d8fe5b78efda91cee3a413f5 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Wed, 6 Oct 2021 22:47:12 +0100 Subject: Update ALLOWED_HOSTS to include internal address --- pydis_site/settings.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'pydis_site/settings.py') diff --git a/pydis_site/settings.py b/pydis_site/settings.py index 35afea22..d7b87f33 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -59,11 +59,7 @@ else: 'pythondiscord.com', gethostname(), gethostbyname(gethostname()), - # "That needs to be there for now, until we move back to... - # no, don't put that there, actually, yeah, put that there, - # that's fine, yeah, no no no no no no, stop it, you're being - # a problem now, I'm phoning [DAD'S NAME]" - Joe - 'pydis-api.default.svc.cluster.local', + 'site.default.svc.cluster.local', ], ) SECRET_KEY = env('SECRET_KEY') -- cgit v1.2.3 From e9c4cdf56e2efd65786a4cf4aee0bb4e4e56bc95 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Sun, 10 Oct 2021 01:28:39 +0300 Subject: Adds Django Distill To Project Adds django-distill to dependencies, and lays the basic groundwork to start building static routes. Adds a poetry task to help with testing. --- manage.py | 31 +++++++++++++++++++++++++++++++ poetry.lock | 17 ++++++++++++++++- pydis_site/settings.py | 21 ++++++++++++++++----- pyproject.toml | 2 ++ 4 files changed, 65 insertions(+), 6 deletions(-) (limited to 'pydis_site/settings.py') diff --git a/manage.py b/manage.py index 578f4748..357134ec 100755 --- a/manage.py +++ b/manage.py @@ -1,6 +1,8 @@ #!/usr/bin/env python import os +import platform import sys +from pathlib import Path import django from django.contrib.auth import get_user_model @@ -147,6 +149,22 @@ class SiteManager: gunicorn.app.wsgiapp.run() +def clean_up_static_files(build_folder: Path) -> None: + """Recursively loop over the build directory and fix links.""" + for file in build_folder.iterdir(): + if file.is_dir(): + clean_up_static_files(file) + elif file.name.endswith(".html"): + # Fix parent host url + new = file.read_text(encoding="utf-8").replace(f"//{os.getenv('PARENT_HOST')}", "") + + # Fix windows paths if on windows + if platform.system() == "Windows": + new = new.replace("%5C", "/") + + file.write_text(new, encoding="utf-8") + + def main() -> None: """Entry point for Django management script.""" # Use the custom site manager for launching the server @@ -155,8 +173,21 @@ def main() -> None: # Pass any others directly to standard management commands else: + if _static_build := "distill" in sys.argv[1]: + # Build a static version of the site with no databases and API support + os.environ["STATIC_BUILD"] = "True" + if not os.getenv("PARENT_HOST"): + os.environ["PARENT_HOST"] = "REPLACE_THIS.HOST" + execute_from_command_line(sys.argv) + if _static_build: + # Clean up parent host in generated files + for arg in sys.argv[2:]: + if not arg.startswith("-"): + clean_up_static_files(Path(arg)) + break + if __name__ == '__main__': main() diff --git a/poetry.lock b/poetry.lock index c6724cfc..eac58fdb 100644 --- a/poetry.lock +++ b/poetry.lock @@ -137,6 +137,18 @@ sqlparse = ">=0.2.2" argon2 = ["argon2-cffi (>=16.1.0)"] bcrypt = ["bcrypt"] +[[package]] +name = "django-distill" +version = "2.9.0" +description = "Static site renderer and publisher for Django." +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +django = "*" +requests = "*" + [[package]] name = "django-environ" version = "0.4.5" @@ -757,7 +769,7 @@ brotli = ["brotli"] [metadata] lock-version = "1.1" python-versions = "3.9.*" -content-hash = "ed7da8dbc905d4f2c47e01301b49c4aed0083bee269da0ee5ebcc3abee4ab1a0" +content-hash = "9f0c069c14e2dbff63d58474702693f0c02b8cfd30e5af38303975a73b71bcfd" [metadata.files] asgiref = [ @@ -858,6 +870,9 @@ django = [ {file = "Django-3.0.14-py3-none-any.whl", hash = "sha256:9bc7aa619ed878fedba62ce139abe663a147dccfd20e907725ec11e02a1ca225"}, {file = "Django-3.0.14.tar.gz", hash = "sha256:d58d8394036db75a81896037d757357e79406e8f68816c3e8a28721c1d9d4c11"}, ] +django-distill = [ + {file = "django-distill-2.9.0.tar.gz", hash = "sha256:08f31dcde2e79e73c0bc4f36941830603a811cc89472be11f79f14affb460d84"}, +] django-environ = [ {file = "django-environ-0.4.5.tar.gz", hash = "sha256:6c9d87660142608f63ec7d5ce5564c49b603ea8ff25da595fd6098f6dc82afde"}, {file = "django_environ-0.4.5-py2.py3-none-any.whl", hash = "sha256:c57b3c11ec1f319d9474e3e5a79134f40174b17c7cc024bbb2fad84646b120c4"}, diff --git a/pydis_site/settings.py b/pydis_site/settings.py index d7b87f33..d38c298b 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -25,7 +25,8 @@ from pydis_site.constants import GIT_SHA env = environ.Env( DEBUG=(bool, False), SITE_DSN=(str, ""), - BUILDING_DOCKER=(bool, False) + BUILDING_DOCKER=(bool, False), + STATIC_BUILD=(bool, False), ) sentry_sdk.init( @@ -65,10 +66,14 @@ else: SECRET_KEY = env('SECRET_KEY') # Application definition -INSTALLED_APPS = [ +NON_STATIC_APPS = [ 'pydis_site.apps.api', - 'pydis_site.apps.home', 'pydis_site.apps.staff', +] if not env("STATIC_BUILD") else [] + +INSTALLED_APPS = [ + *NON_STATIC_APPS, + 'pydis_site.apps.home', 'pydis_site.apps.resources', 'pydis_site.apps.content', 'pydis_site.apps.events', @@ -86,14 +91,20 @@ INSTALLED_APPS = [ 'django_simple_bulma', 'rest_framework', 'rest_framework.authtoken', + + 'django_distill', ] if not env("BUILDING_DOCKER"): INSTALLED_APPS.append("django_prometheus") +NON_STATIC_MIDDLEWARE = [ + 'django_prometheus.middleware.PrometheusBeforeMiddleware', +] if not env("STATIC_BUILD") else [] + # Ensure that Prometheus middlewares are first and last here. MIDDLEWARE = [ - 'django_prometheus.middleware.PrometheusBeforeMiddleware', + *NON_STATIC_MIDDLEWARE, 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', @@ -134,7 +145,7 @@ WSGI_APPLICATION = 'pydis_site.wsgi.application' DATABASES = { 'default': env.db(), 'metricity': env.db('METRICITY_DB_URL'), -} +} if not env("STATIC_BUILD") else {} # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators diff --git a/pyproject.toml b/pyproject.toml index d0beb632..2f1322e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ sentry-sdk = "~=0.19" markdown = "~=3.3.4" python-frontmatter = "~=1.0" django-prometheus = "~=2.1" +django-distill = "~=2.9.0" [tool.poetry.dev-dependencies] coverage = "~=5.0" @@ -53,3 +54,4 @@ test = "coverage run manage.py test" report = "coverage report -m" lint = "pre-commit run --all-files" precommit = "pre-commit install" +static = "python mange.py distill-local build --traceback --force" -- cgit v1.2.3