From 4c0db9f84225e2d443a1d39827b1be1f2758953c Mon Sep 17 00:00:00 2001 From: badbl0cks <4161747+badbl0cks@users.noreply.github.com> Date: Tue, 18 Mar 2025 14:21:50 -0700 Subject: [PATCH] Fix Gravatar profiles showing on hover and add gravatar explanation and profile page for users --- accounts/templatetags/gravatar.py | 11 ++++++++ accounts/urls.py | 2 ++ accounts/views.py | 6 +++++ static/js/base.js | 6 ----- theme/templates/account/profile.html | 26 +++++++++++++++++++ theme/templates/account/settings.html | 2 +- theme/templates/base.html | 36 ++++++++++++++++++++++++--- 7 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 theme/templates/account/profile.html diff --git a/accounts/templatetags/gravatar.py b/accounts/templatetags/gravatar.py index b1dac76..ea47edc 100644 --- a/accounts/templatetags/gravatar.py +++ b/accounts/templatetags/gravatar.py @@ -47,6 +47,17 @@ def gravatar(email, size=20): html = f'Gravatar' return mark_safe(html) +@register.filter +def gravatar_no_hover(email, size=20): + """ + Returns an HTML image tag for the Gravatar of a given email, + with the specified width and height. + """ + url = gravatar_url(email, size) + # Return a safe HTML snippet with the image element + html = f'Gravatar' + return mark_safe(html) + @register.filter def gravatar_profile_data(email): """ diff --git a/accounts/urls.py b/accounts/urls.py index f56852f..597c281 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -6,6 +6,7 @@ from .views import ( ChangeDefaultFriendCodeView, EditFriendCodeView, SettingsView, + ProfileView, ) urlpatterns = [ @@ -16,4 +17,5 @@ urlpatterns = [ path("friend-codes/delete//", DeleteFriendCodeView.as_view(), name="delete_friend_code"), path("friend-codes/default//", ChangeDefaultFriendCodeView.as_view(), name="change_default_friend_code"), path("settings/", SettingsView.as_view(), name="settings"), + path("profile/", ProfileView.as_view(), name="profile"), ] \ No newline at end of file diff --git a/accounts/views.py b/accounts/views.py index c73f8a3..f32c776 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -129,6 +129,12 @@ class SettingsView(LoginRequiredMixin, TemplateView): """ template_name = "account/settings.html" +class ProfileView(LoginRequiredMixin, TemplateView): + """ + Display the user's profile. + """ + template_name = "account/profile.html" + class EditFriendCodeView(LoginRequiredMixin, UpdateView): """ Edit the in-game name for a friend code. diff --git a/static/js/base.js b/static/js/base.js index 2b634e1..ded9290 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -2,12 +2,6 @@ const $ = x => Array.from(document.querySelectorAll(x)); const $$ = x => Array.from(document.querySelector(x)); document.addEventListener('DOMContentLoaded', function() { - // Initialize Gravatar if available - if (typeof Gravatar !== 'undefined' && typeof Gravatar.init === 'function') { - Gravatar.init(); - } - - const themeToggleBtn = document.getElementById('theme-toggle-btn'); if (themeToggleBtn) { themeToggleBtn.addEventListener('click', function() { diff --git a/theme/templates/account/profile.html b/theme/templates/account/profile.html new file mode 100644 index 0000000..50ad857 --- /dev/null +++ b/theme/templates/account/profile.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} +{% load i18n gravatar%} + +{% block head_title %}{% trans "Settings" %}{% endblock %} + +{% block content %} +
+

{% trans "Profile" %}

+
+
+
{{ user.email|gravatar:100 }}
+

All profile information is managed through Gravatar.

+

Edit Profile on Gravatar

+
+

What is Gravatar?

+

Gravatar (Globally Recognized Avatar) is a free service that links your email address to a profile picture and, optionally, a profile. Many websites, including this one, use Gravatar to display your avatar and profile automatically.

+ +

How does it work?

+

If you’ve set up a Gravatar, your profile picture will appear here whenever you use your email on supported sites. When someone hovers over or clicks on your avatar, your Gravatar profile will appear if you have one. If you don’t have a Gravatar yet, you’ll see a default image instead.

+ +

Want to update or add a Gravatar?

+

Go to Gravatar.com to set up or change your avatar or profile. Your updates will appear here once saved!

+
+
+
+{% endblock %} \ No newline at end of file diff --git a/theme/templates/account/settings.html b/theme/templates/account/settings.html index c35555e..f014b4a 100644 --- a/theme/templates/account/settings.html +++ b/theme/templates/account/settings.html @@ -8,7 +8,7 @@

{% trans "Settings" %}