Skip to content

Commit

Permalink
Show flair for new contributors in the selected release.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjp93 committed Sep 30, 2024
1 parent 45a3fa7 commit dca2de1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 24 deletions.
16 changes: 14 additions & 2 deletions libraries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,6 +21,7 @@
from .mixins import VersionAlertMixin
from .models import (
Category,
Commit,
CommitAuthor,
CommitAuthorEmail,
Library,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion templates/libraries/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h2 class="text-2xl">Maintainers &amp; Contributors</h2>

<div class="flex flex-wrap justify-center gap-2">
{% for author in top_contributors_release %}
{% avatar commitauthor=author %}
{% avatar commitauthor=author is_new=author.is_new %}
{% endfor %}
</div>

Expand Down
27 changes: 24 additions & 3 deletions templates/partials/avatar.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,34 @@
{% with av_alt=av_alt|default:av_name av_icon_size=av_icon_size|default:"text-3xl" %}
<a {% if av_href and av_is_link %}href="{{ av_href }}"{% endif %}>
<div class="w-min text-center flex flex-col justify-center items-center">
<div class="bg-gray-300 dark:bg-slate rounded-lg {{ av_size }} flex items-center justify-center relative" title="{{ av_title }}">
<div
class="{{ av_size }} bg-gray-300 dark:bg-slate flex items-center justify-center relative rounded-lg"
title="{{ av_title }}{% if av_is_new %} - NEW!{% endif %}">
{% if av_is_new %}
<div class="absolute top-[-12px] right-[-8px]">
<i class="fas fa-solid fa-star text-sm text-gold"></i>
</div>
{% endif %}
{% if av_image_url %}
<img src="{{ av_image_url }}"
alt="{{ av_alt }}"
class="rounded-lg {{ av_size }} object-cover mx-auto" />
class="
{% if av_is_new %}
border-2 border-gold
{% endif %}
rounded-lg h-full w-full object-cover mx-auto
"
/>
{% else %}
<i class="{{ av_icon_size }} align-middle fas fa-user text-white dark:text-white/60"></i>
<i
class="
{{ av_icon_size }}
align-middle fas fa-user text-white dark:text-white/60
{% if av_is_new %}
border-2 border-gold
{% endif %}
"
></i>
{% endif %}
</div>
{% if av_show_name %}
Expand Down
33 changes: 15 additions & 18 deletions users/templatetags/avatar_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def base_avatar(
title=None,
image_size=None,
icon_size=None,
is_new=False,
):
context = {
"av_name": name,
Expand All @@ -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)

Expand All @@ -40,43 +42,38 @@ 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
return base_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.")

0 comments on commit dca2de1

Please sign in to comment.