Skip to content

Commit d4ea60c

Browse files
author
julioest
committed
fix: Use real GitHub avatar data #2204
Replace fabricated github.com/{username}.png URLs with actual avatar data from CommitAuthor/User thumbnail. Falls back to initials circle instead of static placeholder image.
1 parent 3a97755 commit d4ea60c

1 file changed

Lines changed: 32 additions & 10 deletions

File tree

core/views.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,13 +1071,31 @@ class V3ComponentDemoView(TemplateView):
10711071

10721072
template_name = "base.html"
10731073

1074+
@staticmethod
1075+
def _get_author_avatar(author):
1076+
"""Return the best available avatar URL for a library author (User).
1077+
1078+
Returns empty string when no image is available so the avatar
1079+
template falls back to a colored initials circle.
1080+
"""
1081+
if not author:
1082+
return ""
1083+
url = author.get_thumbnail_url()
1084+
if url:
1085+
return url
1086+
ca = getattr(author, "commitauthor", None)
1087+
if ca and getattr(ca, "avatar_url", None):
1088+
return ca.avatar_url
1089+
return ""
1090+
10741091
def get_context_data(self, **kwargs):
10751092
from django.urls import reverse
10761093
from libraries.models import Library, LibraryVersion
10771094
from libraries.utils import (
10781095
build_library_intro_context,
10791096
get_commit_data_by_release_for_library,
10801097
commit_data_to_stats_bars,
1098+
patch_commit_authors,
10811099
)
10821100

10831101
CODE_DEMO_BEAST = """int main()
@@ -1751,6 +1769,18 @@ def get_context_data(self, **kwargs):
17511769
.prefetch_related("categories", "authors")
17521770
.order_by("name")
17531771
)
1772+
# Collect one author per demo library and patch CommitAuthor data
1773+
demo_authors = {}
1774+
for lib in demo_libs_qs:
1775+
author = (
1776+
lib.authors.exclude(email__startswith="deleted-")
1777+
.exclude(github_username="")
1778+
.first()
1779+
) or lib.authors.exclude(email__startswith="deleted-").first()
1780+
if author:
1781+
demo_authors[lib.pk] = author
1782+
patch_commit_authors(list(demo_authors.values()))
1783+
17541784
for lib in demo_libs_qs:
17551785
lv = (
17561786
LibraryVersion.objects.filter(version=latest, library=lib).first()
@@ -1761,11 +1791,7 @@ def get_context_data(self, **kwargs):
17611791
{"label": cat.name, "url": "#", "variant": "neutral"}
17621792
for cat in lib.categories.all()[:3]
17631793
]
1764-
author = (
1765-
lib.authors.exclude(email__startswith="deleted-")
1766-
.exclude(github_username="")
1767-
.first()
1768-
) or lib.authors.exclude(email__startswith="deleted-").first()
1794+
author = demo_authors.get(lib.pk)
17691795
demo_library_items.append(
17701796
{
17711797
"library_name": lib.display_name_short,
@@ -1786,11 +1812,7 @@ def get_context_data(self, **kwargs):
17861812
"author": {
17871813
"name": author.display_name if author else "Unknown",
17881814
"role": "Contributor",
1789-
"avatar_url": (
1790-
f"https://github.com/{author.github_username}.png"
1791-
if author and author.github_username
1792-
else f"{settings.STATIC_URL}img/v3/demo_page/Avatar.png"
1793-
),
1815+
"avatar_url": self._get_author_avatar(author),
17941816
"badge_url": f"{badge_img}/badge-first-place.png",
17951817
},
17961818
"doc_url": reverse(

0 commit comments

Comments
 (0)