From d4b5560fe300f38338ef3f18b6a601c63ab51c52 Mon Sep 17 00:00:00 2001 From: Brian Perrett Date: Thu, 26 Sep 2024 17:21:53 -0700 Subject: [PATCH 1/4] Create an avatar tag to be usable anywhere we need an avatar. - fixes https://github.com/boostorg/website-v2/issues/1285 - Use a django tag to render an avatar component. --- config/urls.py | 2 - libraries/views.py | 9 ++- templates/admin/library_report_detail.html | 22 ++---- templates/admin/library_stat_detail.html | 18 +---- templates/includes/_header.html | 20 +---- templates/libraries/detail.html | 59 ++------------ templates/partials/avatar.html | 28 +++++-- templates/users/includes/header_avatar.html | 85 +++++++++------------ templates/users/profile_base.html | 14 +--- users/models.py | 5 ++ users/templatetags/__init__.py | 0 users/templatetags/avatar_tags.py | 28 +++++++ users/views.py | 15 ---- 13 files changed, 114 insertions(+), 191 deletions(-) create mode 100644 users/templatetags/__init__.py create mode 100644 users/templatetags/avatar_tags.py diff --git a/config/urls.py b/config/urls.py index bd85fa8d..27f63161 100755 --- a/config/urls.py +++ b/config/urls.py @@ -64,7 +64,6 @@ CustomSignupView, CustomSocialSignupViewView, ProfileView, - UserAvatar, UserViewSet, ) from versions.api import ImportVersionsView, VersionViewSet @@ -99,7 +98,6 @@ path("accounts/", include("allauth.urls")), path("users/me/", CurrentUserProfileView.as_view(), name="profile-account"), path("users//", ProfileView.as_view(), name="profile-user"), - path("users/avatar/", UserAvatar.as_view(), name="user-avatar"), path("api/v1/users/me/", CurrentUserAPIView.as_view(), name="current-user"), path( "api/v1/import-versions/", diff --git a/libraries/views.py b/libraries/views.py index 94c9c84c..b39d4a15 100644 --- a/libraries/views.py +++ b/libraries/views.py @@ -265,9 +265,9 @@ def get_context_data(self, **kwargs): context["maintainers"] = self.get_maintainers(context["version"]) context["author_tag"] = self.get_author_tag() exclude_maintainer_ids = [ - getattr(x.commitauthor, "id") + x.commitauthor.id for x in context["maintainers"] - if x.commitauthor + if getattr(x.commitauthor, "id", None) ] context["top_contributors_release"] = self.get_top_contributors( version=context["version"], @@ -431,7 +431,10 @@ def get_maintainers(self, version): if author_email := commit_authors.get(user.email.lower(), None): user.commitauthor = author_email.author else: - user.commitauthor = None + user.commitauthor = { + "github_profile_url": "", + "avatar_url": "", + } return qs def get_top_contributors(self, version=None, exclude=None): diff --git a/templates/admin/library_report_detail.html b/templates/admin/library_report_detail.html index 1745907f..3c3fcd3f 100644 --- a/templates/admin/library_report_detail.html +++ b/templates/admin/library_report_detail.html @@ -1,4 +1,4 @@ -{% load static humanize %} +{% load static humanize avatar_tags %} @@ -65,14 +65,8 @@

Boost {{ version.display_name }}

{% for author in top_contributors_release_overall %} -
- {% if author.avatar_url %} - {{ author.name }} - {% else %} -
- {% endif %} +
+ {% avatar name=author.name image_url=author.avatar_url href=author.github_profile_url %}
{{ author.name }} @@ -111,14 +105,8 @@

There were {{ item.version_count.commit_count }} commits in release {{ versi
Top Contributors
{% for author in item.top_contributors_release %} -
- {% if author.avatar_url %} - {{ author.name }} - {% else %} -
- {% endif %} +
+ {% avatar name=author.name image_url=author.avatar_url href=author.github_profile_url %}
{{ author.name }} diff --git a/templates/admin/library_stat_detail.html b/templates/admin/library_stat_detail.html index 2807fa23..b244a94b 100644 --- a/templates/admin/library_stat_detail.html +++ b/templates/admin/library_stat_detail.html @@ -1,5 +1,5 @@ {% extends "admin/base_site.html" %} -{% load static %} +{% load static avatar_tags %} {% block extrahead %} {% endblock extrahead %} @@ -33,12 +33,7 @@

{% for author in commits_per_author %}
- {% if author.avatar_url %} - github avatar - {% else %} -
-
- {% endif %} + {% avatar name=author.name image_url=author.avatar_url href=author.github_profile_url %}
{{ author.name }}: {{ author.count }}
@@ -60,14 +55,7 @@


{% endifchanged %}
- {% if item.commit__author__avatar_url %} - github avatar - {% else %} -
-
- {% endif %} + {% avatar name=item.commit__author__name image_url=item.commit__author__avatar_url href=None %}
{{ item.commit__author__name }}: {{ item.count }}
diff --git a/templates/includes/_header.html b/templates/includes/_header.html index c9013b46..f2f39340 100644 --- a/templates/includes/_header.html +++ b/templates/includes/_header.html @@ -403,23 +403,9 @@ {% if not disable_theme_switcher %} {% endif %} - {% comment %} - The html and context for the user avatar and profile dropdown menu are coming from the view as - and html fragment fetched view htmx get request and inserted into #avatar - {% endcomment %} - -
-
- - - -
+ + {% include "users/includes/header_avatar.html" %} +