From dca2de11626e360f0a334e114028726484b5ee58 Mon Sep 17 00:00:00 2001 From: Brian Perrett Date: Fri, 27 Sep 2024 16:04:33 -0700 Subject: [PATCH 1/2] Show flair for new contributors in the selected release. --- libraries/views.py | 16 +++++++++++++-- templates/libraries/detail.html | 2 +- templates/partials/avatar.html | 27 ++++++++++++++++++++++--- users/templatetags/avatar_tags.py | 33 ++++++++++++++----------------- 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/libraries/views.py b/libraries/views.py index f71a4c51..fa403646 100644 --- a/libraries/views.py +++ b/libraries/views.py @@ -5,7 +5,7 @@ import structlog from django.contrib import messages -from django.db.models import F, Count +from django.db.models import F, Count, Exists, OuterRef from django.db.models.functions import Lower from django.http import Http404 from django.shortcuts import get_object_or_404, redirect @@ -21,6 +21,7 @@ from .mixins import VersionAlertMixin from .models import ( Category, + Commit, CommitAuthor, CommitAuthorEmail, Library, @@ -443,7 +444,18 @@ def get_top_contributors(self, version=None, exclude=None): library_version = LibraryVersion.objects.get( library=self.object, version=version ) - qs = CommitAuthor.objects.filter(commit__library_version=library_version) + qs = CommitAuthor.objects.filter( + commit__library_version=library_version + ).annotate( + is_new=~Exists( + Commit.objects.filter( + author_id=OuterRef("id"), + library_version__in=LibraryVersion.objects.filter( + version__name__lt=version.name, library=self.object + ), + ) + ) + ) else: qs = CommitAuthor.objects.filter( commit__library_version__library=self.object diff --git a/templates/libraries/detail.html b/templates/libraries/detail.html index dfe4fcb3..2687a8ad 100644 --- a/templates/libraries/detail.html +++ b/templates/libraries/detail.html @@ -124,7 +124,7 @@

Maintainers & Contributors

{% for author in top_contributors_release %} - {% avatar commitauthor=author %} + {% avatar commitauthor=author is_new=author.is_new %} {% endfor %}
diff --git a/templates/partials/avatar.html b/templates/partials/avatar.html index b309afc6..f5731785 100644 --- a/templates/partials/avatar.html +++ b/templates/partials/avatar.html @@ -3,13 +3,34 @@ {% with av_alt=av_alt|default:av_name av_icon_size=av_icon_size|default:"text-3xl" %}
-
+
+ {% if av_is_new %} +
+ +
+ {% endif %} {% if av_image_url %} {{ av_alt }} + class=" + {% if av_is_new %} + border-2 border-gold + {% endif %} + rounded-lg h-full w-full object-cover mx-auto + " + /> {% else %} - + {% endif %}
{% if av_show_name %} diff --git a/users/templatetags/avatar_tags.py b/users/templatetags/avatar_tags.py index c1424f71..eb8b0610 100644 --- a/users/templatetags/avatar_tags.py +++ b/users/templatetags/avatar_tags.py @@ -15,6 +15,7 @@ def base_avatar( title=None, image_size=None, icon_size=None, + is_new=False, ): context = { "av_name": name, @@ -26,6 +27,7 @@ def base_avatar( "av_icon_size": icon_size, "av_title": title, "av_alt": alt, + "av_is_new": is_new, } return render_to_string("partials/avatar.html", context) @@ -40,7 +42,17 @@ def avatar( title=None, image_size=None, icon_size=None, + is_new=False, ): + kwargs = { + "is_link": is_link, + "is_show_name": is_show_name, + "alt": alt, + "title": title, + "image_size": image_size, + "icon_size": icon_size, + "is_new": is_new, + } if user and commitauthor: image_url = user.get_thumbnail_url() or commitauthor.avatar_url href = user.github_profile_url or commitauthor.github_profile_url @@ -48,35 +60,20 @@ def avatar( user.get_full_name(), image_url, href, - is_link=is_link, - is_show_name=is_show_name, - alt=alt, - title=title, - image_size=image_size, - icon_size=icon_size, + **kwargs, ) elif user: return base_avatar( user.get_full_name(), user.get_thumbnail_url(), user.github_profile_url, - is_link=is_link, - is_show_name=is_show_name, - alt=alt, - title=title, - image_size=image_size, - icon_size=icon_size, + **kwargs, ) elif commitauthor: return base_avatar( commitauthor.name, commitauthor.avatar_url, commitauthor.github_profile_url, - is_link=is_link, - is_show_name=is_show_name, - alt=alt, - title=title, - image_size=image_size, - icon_size=icon_size, + **kwargs, ) raise ValueError("Must provide user or commitauthor.") From 13d296e68161ceedd1c104aa07098ffb2793ccec Mon Sep 17 00:00:00 2001 From: Brian Perrett Date: Mon, 30 Sep 2024 16:29:48 -0700 Subject: [PATCH 2/2] New contributor visual changes. --- libraries/views.py | 20 ++++++++------------ templates/libraries/detail.html | 8 +++++++- templates/partials/avatar.html | 11 ----------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/libraries/views.py b/libraries/views.py index fa403646..7df4897c 100644 --- a/libraries/views.py +++ b/libraries/views.py @@ -271,33 +271,29 @@ def get_context_data(self, **kwargs): for x in context["maintainers"] if getattr(x.commitauthor, "id", None) ] - context["top_contributors_release"] = self.get_top_contributors( + top_contributors_release = self.get_top_contributors( version=context["version"], exclude=exclude_maintainer_ids, ) - exclude_top_contributor_ids = [ - x.id for x in context["top_contributors_release"] + context["top_contributors_release_new"] = [ + x for x in top_contributors_release if x.is_new ] + context["top_contributors_release_old"] = [ + x for x in top_contributors_release if not x.is_new + ] + exclude_top_contributor_ids = [x.id for x in top_contributors_release] context["top_contributors_overall"] = self.get_top_contributors( exclude=exclude_maintainer_ids + exclude_top_contributor_ids ) # Since we need to execute these queries separately anyway, just concatenate # their results instead of making a new query all_contributors = [] - for x in chain( - context["top_contributors_release"], context["top_contributors_overall"] - ): + for x in chain(top_contributors_release, context["top_contributors_overall"]): all_contributors.append( { "name": x.name, } ) - for x in context["maintainers"]: - all_contributors.append( - { - "name": x.get_full_name(), - } - ) all_contributors.sort(key=lambda x: x["name"].lower()) context["all_contributors"] = all_contributors diff --git a/templates/libraries/detail.html b/templates/libraries/detail.html index 2687a8ad..b305e296 100644 --- a/templates/libraries/detail.html +++ b/templates/libraries/detail.html @@ -123,11 +123,17 @@

Maintainers & Contributors

- {% for author in top_contributors_release %} + {% for author in top_contributors_release_new %} {% avatar commitauthor=author is_new=author.is_new %} {% endfor %}
+
+ {% for author in top_contributors_release_old %} + {% avatar commitauthor=author %} + {% endfor %} +
+
{% for author in top_contributors_overall %} {% avatar commitauthor=author %} diff --git a/templates/partials/avatar.html b/templates/partials/avatar.html index f5731785..badaed06 100644 --- a/templates/partials/avatar.html +++ b/templates/partials/avatar.html @@ -6,18 +6,10 @@
- {% if av_is_new %} -
- -
- {% endif %} {% if av_image_url %} {{ av_alt }} @@ -26,9 +18,6 @@ class=" {{ av_icon_size }} align-middle fas fa-user text-white dark:text-white/60 - {% if av_is_new %} - border-2 border-gold - {% endif %} " > {% endif %}