From ba66f7ec42daf0711c4c8a98a93e75b83af2827b Mon Sep 17 00:00:00 2001 From: Brian Perrett Date: Thu, 3 Oct 2024 11:48:02 -0700 Subject: [PATCH] Update avatars. - fixes #1309 --- templates/libraries/detail.html | 43 ++++++++++---------- templates/partials/avatar.html | 66 ++++++++++++++++++++----------- users/templatetags/avatar_tags.py | 31 +++++++++------ 3 files changed, 84 insertions(+), 56 deletions(-) diff --git a/templates/libraries/detail.html b/templates/libraries/detail.html index 4df7c871..21674fef 100644 --- a/templates/libraries/detail.html +++ b/templates/libraries/detail.html @@ -111,40 +111,25 @@ - {% if maintainers or top_contributors_release or top_contributors_overall %} + {% if maintainers or top_contributors_release_new or top_contributors_release_old %}
-

Maintainers & Contributors

+

Release Maintainers & Contributors

-
+
{% for user in maintainers %} - {% avatar user=user commitauthor=user.commitauthor image_size="h-12 w-12" is_show_name=True %} + {% avatar user=user commitauthor=user.commitauthor avatar_type="wide" contributor_label="Maintainer" %} {% endfor %}
-
+
{% for author in top_contributors_release_new %} - {% avatar commitauthor=author is_new=author.is_new %} + {% avatar commitauthor=author avatar_type="wide" contributor_label="New Contributor" %} {% endfor %} -
- -
{% for author in top_contributors_release_old %} - {% avatar commitauthor=author %} + {% avatar commitauthor=author avatar_type="wide" contributor_label="Contributor" %} {% endfor %}
- -
- {% for author in top_contributors_overall %} - {% avatar commitauthor=author %} - {% endfor %} -
- -
- {% for author in all_contributors %} -
{{ author.name }}
- {% endfor %} -
{% endif %} @@ -155,6 +140,20 @@

Maintainers & Contributors

{{ description|safe }} {% endif %} + + {% if top_contributors_overall %} +
+

Previous Contributors

+
+
+ {% for author in top_contributors_overall %} + {% avatar commitauthor=author avatar_type="wide" contributor_label="Contributor" %} + {% endfor %} +
+
+
+ {% endif %} + {% endblock %} {% block footer_js %} diff --git a/templates/partials/avatar.html b/templates/partials/avatar.html index badaed06..cdce39c2 100644 --- a/templates/partials/avatar.html +++ b/templates/partials/avatar.html @@ -1,31 +1,51 @@ {# Intended to be used with a django tag: avatar_tags.avatar #} -{% with av_size=av_size|default:"w-9 h-9" av_show_name=av_show_name|default:False av_title=av_title|default:av_name %} +{% with av_size=av_size|default:"w-9 h-9" av_title=av_title|default:av_name %} {% with av_alt=av_alt|default:av_name av_icon_size=av_icon_size|default:"text-3xl" %} - -
-
- {% if av_image_url %} - {{ av_alt }} + +
+
+ {% if av_image_url %} + {{ av_alt }} + {% else %} + - {% else %} - + {% endif %} +
+
+
+ {% if av_avatar_type == "wide" %} +
+
+ {{ av_name }} +
+
- {% endif %} + > + {{ av_contributor_label }} +
- {% if av_show_name %} - {{ av_name }} - {% endif %} -
- + {% endif %} +
{% endwith %} {% endwith %} diff --git a/users/templatetags/avatar_tags.py b/users/templatetags/avatar_tags.py index eb8b0610..990a0068 100644 --- a/users/templatetags/avatar_tags.py +++ b/users/templatetags/avatar_tags.py @@ -1,3 +1,4 @@ +from typing import Literal from django import template from django.template.loader import render_to_string @@ -10,24 +11,24 @@ def base_avatar( image_url, href, is_link=True, - is_show_name=False, alt=None, title=None, image_size=None, icon_size=None, - is_new=False, + contributor_label=None, + avatar_type: None | Literal["wide"] = None, ): context = { "av_name": name, "av_href": href, "av_is_link": is_link, "av_image_url": image_url, - "av_show_name": is_show_name, "av_size": image_size, "av_icon_size": icon_size, "av_title": title, "av_alt": alt, - "av_is_new": is_new, + "av_contributor_label": contributor_label, + "av_avatar_type": avatar_type, } return render_to_string("partials/avatar.html", context) @@ -37,21 +38,21 @@ def avatar( user=None, commitauthor=None, is_link=True, - is_show_name=False, alt=None, title=None, image_size=None, icon_size=None, - is_new=False, + contributor_label=None, + avatar_type=None, ): 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, + "contributor_label": contributor_label, + "avatar_type": avatar_type, } if user and commitauthor: image_url = user.get_thumbnail_url() or commitauthor.avatar_url @@ -70,10 +71,18 @@ def avatar( **kwargs, ) elif commitauthor: + if isinstance(commitauthor, dict): + name = commitauthor["name"] + avatar_url = commitauthor["avatar_url"] + github_profile_url = commitauthor["github_profile_url"] + else: + name = commitauthor.name + avatar_url = commitauthor.avatar_url + github_profile_url = commitauthor.github_profile_url return base_avatar( - commitauthor.name, - commitauthor.avatar_url, - commitauthor.github_profile_url, + name, + avatar_url, + github_profile_url, **kwargs, ) raise ValueError("Must provide user or commitauthor.")