From 2871fe15595c061e8da3411bac65ab4d1e14dbbc Mon Sep 17 00:00:00 2001 From: Vivaan Verma Date: Mon, 17 May 2021 19:18:03 +0100 Subject: [PATCH 1/9] Removed mobile-only banner showcasing 100K members --- pydis_site/templates/home/index.html | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/pydis_site/templates/home/index.html b/pydis_site/templates/home/index.html index 18f6b77b2..092615563 100644 --- a/pydis_site/templates/home/index.html +++ b/pydis_site/templates/home/index.html @@ -9,19 +9,6 @@ {% block content %} {% include "base/navbar.html" %} - -
-
-

100K Member Milestone!

-
-
- Thanks to all our members for helping us create this friendly and helpful community! -

- As a nice treat, we've created a Timeline page for people - to discover the events that made our community what it is today. Be sure to check it out! -
-
-
From ffb7af7342da512fcf6cf5e7ec961ee50ad2de2f Mon Sep 17 00:00:00 2001 From: Vivaan Verma Date: Mon, 17 May 2021 19:19:25 +0100 Subject: [PATCH 2/9] Make timeline look better on mobile --- pydis_site/templates/home/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydis_site/templates/home/index.html b/pydis_site/templates/home/index.html index 092615563..801bb887f 100644 --- a/pydis_site/templates/home/index.html +++ b/pydis_site/templates/home/index.html @@ -85,8 +85,8 @@

Who are we?

- - + + From 1b99709c200fd7a8eeb0607503d7e038e9e262a7 Mon Sep 17 00:00:00 2001 From: Vivaan Verma Date: Tue, 18 May 2021 20:18:03 +0100 Subject: [PATCH 3/9] Added button without github functionality yet --- pydis_site/templates/content/base.html | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pydis_site/templates/content/base.html b/pydis_site/templates/content/base.html index 218954798..0ff969130 100644 --- a/pydis_site/templates/content/base.html +++ b/pydis_site/templates/content/base.html @@ -33,7 +33,17 @@
-

{{ page_title }}

+
+

{{ page_title }}

+ {# TODO: Bikeshed the button design #} + +
{% block page_content %}{% endblock %}
From 69188b27eebf8d76fb5e37f466cabd51d3463627 Mon Sep 17 00:00:00 2001 From: Vivaan Verma Date: Wed, 19 May 2021 21:56:57 +0100 Subject: [PATCH 4/9] Create template tag to return the current page's github file --- pydis_site/apps/content/templatetags/__init__.py | 0 pydis_site/apps/content/templatetags/page_github.py | 11 +++++++++++ 2 files changed, 11 insertions(+) create mode 100644 pydis_site/apps/content/templatetags/__init__.py create mode 100644 pydis_site/apps/content/templatetags/page_github.py diff --git a/pydis_site/apps/content/templatetags/__init__.py b/pydis_site/apps/content/templatetags/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pydis_site/apps/content/templatetags/page_github.py b/pydis_site/apps/content/templatetags/page_github.py new file mode 100644 index 000000000..ec7631e97 --- /dev/null +++ b/pydis_site/apps/content/templatetags/page_github.py @@ -0,0 +1,11 @@ +from django import template + +register = template.Library() + + +@register.filter() +def page_github(current_uri: str): + return current_uri.replace( + "https://pythondiscord.com/pages/", + "https://github.com/python-discord/site/tree/main/pydis_site/apps/content/resources" + ) From 40ccb3a1dabaaa888c81245984d9103981c27986 Mon Sep 17 00:00:00 2001 From: Vivaan Verma Date: Thu, 20 May 2021 18:20:45 +0100 Subject: [PATCH 5/9] Updated custom template tag to not throw 404s --- pydis_site/apps/content/templatetags/page_github.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pydis_site/apps/content/templatetags/page_github.py b/pydis_site/apps/content/templatetags/page_github.py index ec7631e97..b4d631a7e 100644 --- a/pydis_site/apps/content/templatetags/page_github.py +++ b/pydis_site/apps/content/templatetags/page_github.py @@ -1,11 +1,16 @@ from django import template +import requests register = template.Library() @register.filter() def page_github(current_uri: str): - return current_uri.replace( - "https://pythondiscord.com/pages/", - "https://github.com/python-discord/site/tree/main/pydis_site/apps/content/resources" + github_uri = current_uri.replace( + "http://pythondiscord.local:8000/pages/", + "https://github.com/python-discord/site/tree/main/pydis_site/apps/content/resources/" ) + github_uri = github_uri[:-1] if github_uri.endswith("/") else github_uri + if requests.get(github_uri).status_code == 404: + github_uri += ".md" + return github_uri From bc6275bb4f016879b1aecd4753ff50fc36666058 Mon Sep 17 00:00:00 2001 From: Vivaan Verma Date: Thu, 20 May 2021 18:21:14 +0100 Subject: [PATCH 6/9] Update template to use the custom template tag --- pydis_site/templates/content/base.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pydis_site/templates/content/base.html b/pydis_site/templates/content/base.html index 0ff969130..e5c7fb6f6 100644 --- a/pydis_site/templates/content/base.html +++ b/pydis_site/templates/content/base.html @@ -1,5 +1,6 @@ {% extends 'base/base.html' %} {% load static %} +{% load page_github %} {% block title %}{{ page_title }}{% endblock %} {% block head %} @@ -38,9 +39,9 @@

{{ page_title }}

{# TODO: Bikeshed the button design #} From 09f4de915cd1ea03a57892fd05972d69506c0d14 Mon Sep 17 00:00:00 2001 From: Vivaan Verma Date: Thu, 20 May 2021 18:37:08 +0100 Subject: [PATCH 7/9] Fix linting errors on custom template tag --- pydis_site/apps/content/templatetags/page_github.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pydis_site/apps/content/templatetags/page_github.py b/pydis_site/apps/content/templatetags/page_github.py index b4d631a7e..7a4356fe7 100644 --- a/pydis_site/apps/content/templatetags/page_github.py +++ b/pydis_site/apps/content/templatetags/page_github.py @@ -1,11 +1,16 @@ -from django import template import requests +from django import template register = template.Library() @register.filter() -def page_github(current_uri: str): +def page_github(current_uri: str) -> str: + """ + Return the corresponding GitHub page for the current site page. + + Return a directory if the page is a directory on GitHub otherwise return the Markdown file + """ github_uri = current_uri.replace( "http://pythondiscord.local:8000/pages/", "https://github.com/python-discord/site/tree/main/pydis_site/apps/content/resources/" From 4f10de225e3f3e3f20d62f5efef070738a1e6fa9 Mon Sep 17 00:00:00 2001 From: Vivaan Verma <54081925+doublevcodes@users.noreply.github.com> Date: Thu, 27 May 2021 19:24:56 +0100 Subject: [PATCH 8/9] Remove extraneous space Co-authored-by: Kieran Siek --- pydis_site/templates/content/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/templates/content/base.html b/pydis_site/templates/content/base.html index e5c7fb6f6..813702220 100644 --- a/pydis_site/templates/content/base.html +++ b/pydis_site/templates/content/base.html @@ -41,7 +41,7 @@

{{ page_title }}

{# TODO: Make it load the Github page instead of reloading the page #} - Edit on Github + Edit on Github From acdd9e3aea882f4c08e40b46e8b6fa1d91c56874 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Mon, 16 Aug 2021 02:47:54 +0300 Subject: [PATCH 9/9] Adds Github Path Meta Tag Adds a new meta tag to all templates "github-path", which contains the relative path to the template. Signed-off-by: Hassan Abouelela --- pydis_site/context_processors.py | 26 +++++++++++++++++++++++++- pydis_site/settings.py | 3 ++- pydis_site/templates/base/base.html | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/pydis_site/context_processors.py b/pydis_site/context_processors.py index 6937a3db6..0befdf9da 100644 --- a/pydis_site/context_processors.py +++ b/pydis_site/context_processors.py @@ -1,8 +1,32 @@ +import inspect +from pathlib import Path + +from django.http import HttpRequest from django.template import RequestContext from pydis_site.constants import GIT_SHA -def git_sha_processor(_: RequestContext) -> dict: +def git_sha_processor(_: HttpRequest) -> dict: """Expose the git SHA for this repo to all views.""" return {'git_sha': GIT_SHA} + + +def path_processor(_: HttpRequest) -> dict: + """Expose each view's path to itself.""" + # This is a disgusting hack, here's how it works in detail: + # + # 1. We use inspect to pull all the local variables from the previous frame, and access self + # 1a. The previous frame is a django internal which calls context processors, + # and has access to the template + # 1b. The caller is a method in RequestContext, hence self is an instance of RequestContext + # + # 2. We use RequestContext.template to get the Template object, + # which has an absolute path to the template + # + # 3. We use pathlib to create a relative path to the root directory of the project + + context: RequestContext = inspect.currentframe().f_back.f_locals["self"] + + path = Path(context.template.origin.name).relative_to(Path.cwd()) + return {"path": path} diff --git a/pydis_site/settings.py b/pydis_site/settings.py index 7df7ad854..e87df94ec 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -118,7 +118,8 @@ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', - "pydis_site.context_processors.git_sha_processor" + "pydis_site.context_processors.git_sha_processor", + "pydis_site.context_processors.path_processor" ], }, }, diff --git a/pydis_site/templates/base/base.html b/pydis_site/templates/base/base.html index 906fc577e..fdc97711c 100644 --- a/pydis_site/templates/base/base.html +++ b/pydis_site/templates/base/base.html @@ -31,6 +31,7 @@ {% block head %}{% endblock %} +