Update avatars to add hq_image, use with fiscal committee list (#1869(

This commit is contained in:
Dave O'Connor
2025-08-18 17:46:08 -07:00
committed by Kari Skinner
parent adebb47258
commit bf7041184d
3 changed files with 16 additions and 4 deletions

View File

@@ -292,6 +292,12 @@ class User(BaseUser):
with suppress(AttributeError, MissingSource):
return getattr(self.image_thumbnail, "url", None)
def get_hq_image_url(self):
# convenience method for templates
if self.hq_image and self.hq_image_render:
with suppress(AttributeError, MissingSource):
return getattr(self.hq_image_render, "url", None)
@property
def github_profile_url(self):
if not self.github_username:

View File

@@ -44,6 +44,7 @@ def avatar(
icon_size=None,
contributor_label=None,
avatar_type=None,
use_user_hq_image=False,
):
def get_commit_author_attribute(commitauthor, attribute):
if isinstance(commitauthor, dict):
@@ -64,22 +65,27 @@ def avatar(
}
if user and commitauthor:
image_url = user.get_thumbnail_url() or get_commit_author_attribute(
std_image = user.get_thumbnail_url() or get_commit_author_attribute(
commitauthor, "avatar_url"
)
hq_image = user.get_hq_image_url()
use_hq_image = use_user_hq_image and hq_image
href = user.github_profile_url or get_commit_author_attribute(
commitauthor, "github_profile_url"
)
return base_avatar(
commitauthor.display_name,
image_url,
hq_image if use_hq_image else std_image,
href,
**kwargs,
)
elif user:
std_image = user.get_thumbnail_url()
hq_image = user.get_hq_image_url()
use_hq_image = use_user_hq_image and hq_image
return base_avatar(
user.display_name,
user.get_thumbnail_url(),
hq_image if use_hq_image else std_image,
user.github_profile_url,
**kwargs,
)