Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show flair for new contributors in the selected release. #1299

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 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 @@ -270,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
Expand Down Expand Up @@ -443,7 +440,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
8 changes: 7 additions & 1 deletion templates/libraries/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ <h2 class="text-2xl">Maintainers &amp; Contributors</h2>
</div>

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

<div class="flex flex-wrap justify-center gap-2">
{% for author in top_contributors_release_old %}
{% avatar commitauthor=author %}
{% endfor %}
</div>
Expand Down
16 changes: 13 additions & 3 deletions templates/partials/avatar.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
{% 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_image_url %}
<img src="{{ av_image_url }}"
alt="{{ av_alt }}"
class="rounded-lg {{ av_size }} object-cover mx-auto" />
class="
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
"
></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.")