diff --git a/libraries/views.py b/libraries/views.py index 94c9c84c..4c111470 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/libraries/detail.html b/templates/libraries/detail.html index 6999e719..5fc3c515 100644 --- a/templates/libraries/detail.html +++ b/templates/libraries/detail.html @@ -1,6 +1,5 @@ {% extends "base.html" %} -{% load i18n %} -{% load static %} +{% load i18n static avatar_tags %} {% block title %}{{ object.display_name }} ({{ version.display_name }}){% endblock %} {% block description %}{% trans object.description %}{% endblock %} @@ -117,65 +116,21 @@

Maintainers & Contributors

-
+
{% for user in maintainers %} - -
-
- {% if user.image or user.commitauthor.avatar_url %} - {{ user.get_full_name }} - {% else %} - - {% endif %} -
- {{ user.get_full_name }} -
-
+ {% avatar image_url=user.image|default:user.commitauthor.avatar_url href=user.commitauthor.github_profile_url name=user.get_full_name image_size="h-12 w-12" is_show_name=True %} {% endfor %}
-
+
{% for author in top_contributors_release %} - -
-
- {% if author.avatar_url %} - {{ author.name }} - {% else %} - - {% endif %} -
-
-
+ {% avatar image_url=author.avatar_url href=author.github_profile_url name=author.name %} {% endfor %}
-
+
{% for author in top_contributors_overall %} - -
-
- {% if author.avatar_url %} - {{ author.name }} - {% else %} - - {% endif %} -
-
-
+ {% avatar image_url=author.avatar_url href=author.github_profile_url name=author.name %} {% endfor %}
diff --git a/templates/partials/avatar.html b/templates/partials/avatar.html index 9e1f1a33..ed7ba8e0 100644 --- a/templates/partials/avatar.html +++ b/templates/partials/avatar.html @@ -1,7 +1,20 @@ -{% if profile.avatar %} -{{ profile.user }} -{% elif show_placeholder %} - - - -{% endif %} +{# 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 av_alt=av_alt|default:av_name %} + +
+
+ {% if av_image_url %} + {{ av_alt }} + {% else %} + + {% endif %} +
+ {% if av_show_name %} + {{ av_name }} + {% endif %} +
+
+{% endwith %} diff --git a/users/templatetags/__init__.py b/users/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/users/templatetags/avatar_tags.py b/users/templatetags/avatar_tags.py new file mode 100644 index 00000000..63273869 --- /dev/null +++ b/users/templatetags/avatar_tags.py @@ -0,0 +1,26 @@ +from django import template +from django.template.loader import render_to_string + +register = template.Library() + + +@register.simple_tag() +def avatar( + name, + image_url, + href, + is_show_name=False, + alt=None, + title=None, + image_size=None, +): + context = { + "av_name": name, + "av_href": href, + "av_image_url": image_url, + "av_show_name": is_show_name, + "av_size": image_size, + "av_title": title, + "av_alt": alt, + } + return render_to_string("partials/avatar.html", context)