From 1ced4fc37f2969765feac4f090d42148ad4377e9 Mon Sep 17 00:00:00 2001
From: Leon Sandøy
Date: Tue, 1 Oct 2019 22:55:19 +0200
Subject: Update the landing page text.
The new text was written by Tizzysaurus in his website cleanup
project, and lifted from his google doc.
---
pydis_site/templates/home/index.html | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
(limited to 'pydis_site/templates')
diff --git a/pydis_site/templates/home/index.html b/pydis_site/templates/home/index.html
index 205e92ff..bccea71a 100644
--- a/pydis_site/templates/home/index.html
+++ b/pydis_site/templates/home/index.html
@@ -19,21 +19,21 @@
We're a large community focused around the Python programming language.
- We believe anyone can learn programming, and are very dedicated to helping
- novice developers take their first steps into the world of code. We also
+ We believe anyone can learn to code, and are very dedicated to helping
+ novice developers take their first steps into the world of programming. We also
attract a lot of expert developers who are seeking friendships, collaborators,
- or looking to hone their craft by teaching and getting involved in the community.
+ or to hone their craft by teaching and getting involved with the community.
- We organise regular community events like code jams, open source hackathons,
- seasonal events and community challenges. Through our sponsorships and with
- help from donations, we are even able to award prizes to the winners of our events.
+ We organise regular community events such as code jams, open-source hackathons,
+ seasonal events and community challenges. Through our sponsorships, and with
+ the help from donations, many of our events even have prizes to win!
You can find help with most Python-related problems in one of our help channels.
- Our staff of nearly 50 dedicated expert Helpers are available around the clock
+ Our staff of over 50 dedicated expert Helpers, are available around the clock
in every timezone. Whether you're looking to learn the language or working on a
complex project, we've got someone who can help you if you get stuck.
--
cgit v1.2.3
From 0c43428ef86666dfb9d4baf119b0a30ba8dbe5cf Mon Sep 17 00:00:00 2001
From: Leon Sandøy
Date: Sat, 5 Oct 2019 09:20:23 +0200
Subject: Address code review from Scragly and Mark.
Makes various minor changes to commas and formulations.
---
pydis_site/templates/home/index.html | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'pydis_site/templates')
diff --git a/pydis_site/templates/home/index.html b/pydis_site/templates/home/index.html
index bccea71a..bf217fe8 100644
--- a/pydis_site/templates/home/index.html
+++ b/pydis_site/templates/home/index.html
@@ -22,18 +22,18 @@
We believe anyone can learn to code, and are very dedicated to helping
novice developers take their first steps into the world of programming. We also
attract a lot of expert developers who are seeking friendships, collaborators,
- or to hone their craft by teaching and getting involved with the community.
+ and who wish to hone their craft by teaching and getting involved in the community.
We organise regular community events such as code jams, open-source hackathons,
- seasonal events and community challenges. Through our sponsorships, and with
- the help from donations, many of our events even have prizes to win!
+ seasonal events, and community challenges. Through our sponsorships and donations,
+ many of our events even have prizes to win!
You can find help with most Python-related problems in one of our help channels.
- Our staff of over 50 dedicated expert Helpers, are available around the clock
+ Our staff of over 50 dedicated expert Helpers are available around the clock
in every timezone. Whether you're looking to learn the language or working on a
complex project, we've got someone who can help you if you get stuck.
--
cgit v1.2.3
From 23f7f9e5f09e7b5b52810d19ffe7ad31eeabd054 Mon Sep 17 00:00:00 2001
From: Gareth Coles
Date: Sat, 5 Oct 2019 14:49:29 +0100
Subject: Add MessageRedirectView and show messages on the index page
---
pydis_site/settings.py | 10 ++++++++++
pydis_site/static/css/base/base.css | 8 ++++++++
pydis_site/templates/home/index.html | 16 ++++++++++++++++
pydis_site/utils/views.py | 25 +++++++++++++++++++++++++
4 files changed, 59 insertions(+)
create mode 100644 pydis_site/utils/views.py
(limited to 'pydis_site/templates')
diff --git a/pydis_site/settings.py b/pydis_site/settings.py
index 21841e15..919547de 100644
--- a/pydis_site/settings.py
+++ b/pydis_site/settings.py
@@ -272,6 +272,16 @@ LOGGING = {
}
}
+# Django Messages framework config
+
+MESSAGE_TAGS = {
+ messages.DEBUG: 'primary',
+ messages.INFO: 'info',
+ messages.SUCCESS: 'success',
+ messages.WARNING: 'warning',
+ messages.ERROR: 'danger',
+}
+
# Custom settings for Crispyforms
CRISPY_ALLOWED_TEMPLATE_PACKS = (
"bootstrap",
diff --git a/pydis_site/static/css/base/base.css b/pydis_site/static/css/base/base.css
index ce1503a3..283e89cb 100644
--- a/pydis_site/static/css/base/base.css
+++ b/pydis_site/static/css/base/base.css
@@ -70,3 +70,11 @@ div.card.has-equal-height {
#pydis-text {
font-weight: bold;
}
+
+button.is-size-navbar-menu {
+ font-size: 14px;
+}
+
+section.message-section {
+ padding: 1.5rem 1.5rem 0 1.5rem;
+}
diff --git a/pydis_site/templates/home/index.html b/pydis_site/templates/home/index.html
index 205e92ff..a367fe70 100644
--- a/pydis_site/templates/home/index.html
+++ b/pydis_site/templates/home/index.html
@@ -9,6 +9,22 @@
{% block content %}
{% include "base/navbar.html" %}
+ {% if messages %}
+
+
+
+ {% for message in messages %}
+
+
+
+ {{ message }}
+
+ {% endfor %}
+
+
+
+ {% endif %}
+
{# Who are we? #}
diff --git a/pydis_site/utils/views.py b/pydis_site/utils/views.py
new file mode 100644
index 00000000..c9803bd6
--- /dev/null
+++ b/pydis_site/utils/views.py
@@ -0,0 +1,25 @@
+from django.contrib import messages
+from django.http import HttpRequest
+from django.views.generic import RedirectView
+
+
+class MessageRedirectView(RedirectView):
+ """
+ Redirects to another URL, also setting a message using the Django Messages framework.
+
+ This is based on Django's own `RedirectView` and works the same way, but takes two additional
+ parameters.
+
+ * `message`: Set to the message content you wish to display.
+ * `message_level`: Set to one of the message levels from the Django messages framework. This
+ parameter defaults to `messages.INFO`.
+ """
+
+ message: str = ""
+ message_level: int = messages.INFO
+
+ def get(self, request: HttpRequest, *args, **kwargs) -> None:
+ """Called upon a GET request."""
+ messages.add_message(request, self.message_level, self.message)
+
+ return super().get(request, *args, **kwargs)
--
cgit v1.2.3
From 0ebaa16646ad3723a6c365ebe4208586216b609c Mon Sep 17 00:00:00 2001
From: Gareth Coles
Date: Sat, 5 Oct 2019 14:50:24 +0100
Subject: Set up needed Allauth URLs and add login/logout to navbar
---
pydis_site/apps/home/urls.py | 24 +++++++++++++++++++++++-
pydis_site/settings.py | 1 +
pydis_site/templates/base/navbar.html | 21 +++++++++++++++++++++
3 files changed, 45 insertions(+), 1 deletion(-)
(limited to 'pydis_site/templates')
diff --git a/pydis_site/apps/home/urls.py b/pydis_site/apps/home/urls.py
index b9e7341b..dbb53cb6 100644
--- a/pydis_site/apps/home/urls.py
+++ b/pydis_site/apps/home/urls.py
@@ -1,15 +1,37 @@
+from allauth.account.views import LogoutView
+from allauth.socialaccount.views import ConnectionsView
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
+from django.contrib.messages import ERROR
from django.urls import include, path
+from pydis_site.utils.views import MessageRedirectView
from .views import HomeView
app_name = 'home'
urlpatterns = [
path('', HomeView.as_view(), name='home'),
path('pages/', include('wiki.urls')),
- path('accounts/', include('allauth.urls'), name='auth'),
+
+ path('accounts/', include('allauth.socialaccount.providers.discord.urls')),
+ path('accounts/', include('allauth.socialaccount.providers.github.urls')),
+
+ path(
+ 'accounts/login/cancelled', MessageRedirectView.as_view(
+ pattern_name="home", message="Login cancelled."
+ ), name='socialaccount_login_cancelled'
+ ),
+ path(
+ 'accounts/login/error', MessageRedirectView.as_view(
+ pattern_name="home", message="Login failed due to an error, please try again.",
+ message_level=ERROR
+ ), name='socialaccount_login_error'
+ ),
+
+ path('connections', ConnectionsView.as_view()),
+ path('logout', LogoutView.as_view(), name="logout"),
+
path('admin/', admin.site.urls),
path('notifications/', include('django_nyt.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
diff --git a/pydis_site/settings.py b/pydis_site/settings.py
index 919547de..cc741117 100644
--- a/pydis_site/settings.py
+++ b/pydis_site/settings.py
@@ -376,3 +376,4 @@ AUTHENTICATION_BACKENDS = (
)
ACCOUNT_EMAIL_VERIFICATION = "none" # No verification required; we don't use emails for anything
+LOGIN_REDIRECT_URL = "home"
diff --git a/pydis_site/templates/base/navbar.html b/pydis_site/templates/base/navbar.html
index ee68852a..e73864fe 100644
--- a/pydis_site/templates/base/navbar.html
+++ b/pydis_site/templates/base/navbar.html
@@ -1,3 +1,5 @@
+{% load account %}
+{% load socialaccount %}
{% load static %}
--
cgit v1.2.3
From c44b5a740a69de5b479100f4c023bb80db8605a6 Mon Sep 17 00:00:00 2001
From: Leon Sandøy
Date: Sat, 5 Oct 2019 17:47:05 +0200
Subject: Make the homepage paragraphier.
---
pydis_site/templates/home/index.html | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
(limited to 'pydis_site/templates')
diff --git a/pydis_site/templates/home/index.html b/pydis_site/templates/home/index.html
index bf217fe8..45fb56e9 100644
--- a/pydis_site/templates/home/index.html
+++ b/pydis_site/templates/home/index.html
@@ -23,15 +23,13 @@
novice developers take their first steps into the world of programming. We also
attract a lot of expert developers who are seeking friendships, collaborators,
and who wish to hone their craft by teaching and getting involved in the community.
-
-
-
+
+
We organise regular community events such as code jams, open-source hackathons,
seasonal events, and community challenges. Through our sponsorships and donations,
many of our events even have prizes to win!
-
-
-
+
+
You can find help with most Python-related problems in one of our help channels.
Our staff of over 50 dedicated expert Helpers are available around the clock
in every timezone. Whether you're looking to learn the language or working on a
--
cgit v1.2.3
From 486b37b9aeac4a3389aba43970a46024b7ee8c65 Mon Sep 17 00:00:00 2001
From: Gareth Coles
Date: Sun, 6 Oct 2019 12:33:53 +0100
Subject: Move messages to the top right
---
pydis_site/static/css/base/base.css | 25 +++++++++++++++++++++++--
pydis_site/templates/base/base.html | 12 ++++++++++++
pydis_site/templates/home/index.html | 16 ----------------
3 files changed, 35 insertions(+), 18 deletions(-)
(limited to 'pydis_site/templates')
diff --git a/pydis_site/static/css/base/base.css b/pydis_site/static/css/base/base.css
index 283e89cb..256bec2c 100644
--- a/pydis_site/static/css/base/base.css
+++ b/pydis_site/static/css/base/base.css
@@ -71,10 +71,31 @@ div.card.has-equal-height {
font-weight: bold;
}
+
+/* Fix for logout form submit button in navbar */
+
button.is-size-navbar-menu {
font-size: 14px;
}
-section.message-section {
- padding: 1.5rem 1.5rem 0 1.5rem;
+/* On-page message styling */
+
+@keyframes message-slide-in {
+ 0% {
+ transform: translateX(100%);
+ }
+
+ 100% {
+ transform: translateX(0);
+ }
+}
+
+div.messages {
+ animation: 0.5s ease-out 0s 1 message-slide-in;
+ padding: 0.5rem;
+ position: fixed;
+ right: 0;
+ top: 76px;
+
+ z-index: 1000; /* On top of everything else */
}
diff --git a/pydis_site/templates/base/base.html b/pydis_site/templates/base/base.html
index a419521c..7b197be3 100644
--- a/pydis_site/templates/base/base.html
+++ b/pydis_site/templates/base/base.html
@@ -26,6 +26,18 @@
+ {% if messages %}
+
--
cgit v1.2.3
From e736381dc00b495a853b4aa71f1a4f381f665a76 Mon Sep 17 00:00:00 2001
From: Gareth Coles
Date: Sun, 6 Oct 2019 21:27:11 +0100
Subject: Prevent saving emails, remove login page
---
pydis_site/apps/home/apps.py | 24 +++++++++++++++++
pydis_site/apps/home/urls.py | 2 --
pydis_site/apps/home/views/login.py | 31 ----------------------
pydis_site/templates/base/navbar.html | 13 ++++++---
pydis_site/templates/home/login.html | 50 -----------------------------------
5 files changed, 34 insertions(+), 86 deletions(-)
delete mode 100644 pydis_site/apps/home/views/login.py
delete mode 100644 pydis_site/templates/home/login.html
(limited to 'pydis_site/templates')
diff --git a/pydis_site/apps/home/apps.py b/pydis_site/apps/home/apps.py
index 055d721b..a7c47dc5 100644
--- a/pydis_site/apps/home/apps.py
+++ b/pydis_site/apps/home/apps.py
@@ -1,3 +1,5 @@
+from typing import Any, Dict
+
from django.apps import AppConfig
@@ -12,3 +14,25 @@ class HomeConfig(AppConfig):
from pydis_site.apps.home.signals import SignalListener
self.signal_listener = SignalListener()
+ self.patch_allauth()
+
+ def patch_allauth(self) -> None:
+ """Monkey-patches Allauth classes so we never collect email addresses."""
+ # Imported here because we can't import it before our apps are loaded up
+ from allauth.socialaccount.providers.base import Provider
+
+ def extract_extra_data(_: Provider, data: Dict[str, Any]) -> Dict[str, Any]:
+ """
+ Extracts extra data for a SocialAccount provided by Allauth.
+
+ This is our version of this function that strips the email address from incoming extra
+ data. We do this so that we never have to store it.
+
+ This is monkey-patched because most OAuth providers - or at least the ones we care
+ about - all use the function from the base Provider class. This means we don't have
+ to make a new Django app for each one we want to work with.
+ """
+ data["email"] = ""
+ return data
+
+ Provider.extract_extra_data = extract_extra_data
diff --git a/pydis_site/apps/home/urls.py b/pydis_site/apps/home/urls.py
index 150b5b12..dbb53cb6 100644
--- a/pydis_site/apps/home/urls.py
+++ b/pydis_site/apps/home/urls.py
@@ -6,7 +6,6 @@ from django.contrib import admin
from django.contrib.messages import ERROR
from django.urls import include, path
-from pydis_site.apps.home.views.login import LoginView
from pydis_site.utils.views import MessageRedirectView
from .views import HomeView
@@ -31,7 +30,6 @@ urlpatterns = [
),
path('connections', ConnectionsView.as_view()),
- path('login', LoginView.as_view(), name="login"),
path('logout', LogoutView.as_view(), name="logout"),
path('admin/', admin.site.urls),
diff --git a/pydis_site/apps/home/views/login.py b/pydis_site/apps/home/views/login.py
deleted file mode 100644
index d74403a8..00000000
--- a/pydis_site/apps/home/views/login.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from allauth.socialaccount.providers import registry
-from allauth.socialaccount.providers.discord.provider import DiscordProvider
-from django.contrib import messages
-from django.http import HttpRequest, HttpResponse
-from django.shortcuts import redirect
-from django.views.generic import View
-from django.views.generic.base import TemplateResponseMixin
-
-
-class LoginView(View, TemplateResponseMixin):
- """Login view for collecting email collection consent from users."""
-
- template_name = "home/login.html"
-
- def get(self, request: HttpRequest) -> HttpResponse:
- """Render the login page view."""
- return self.render_to_response({})
-
- def post(self, request: HttpRequest) -> HttpResponse:
- """Check whether the user provided consent, and action appropriately."""
- if request.POST.get("consent", None) != "on": # I bet IE breaks this standard...
- messages.add_message(
- request,
- messages.ERROR,
- "Consent is required to login with Discord.",
- )
-
- return self.render_to_response({})
-
- provider: DiscordProvider = registry.by_id("discord")
- return redirect(provider.get_login_url(request))
diff --git a/pydis_site/templates/base/navbar.html b/pydis_site/templates/base/navbar.html
index f51f7c53..1d30b8f0 100644
--- a/pydis_site/templates/base/navbar.html
+++ b/pydis_site/templates/base/navbar.html
@@ -1,3 +1,4 @@
+{% load socialaccount %}
{% load static %}