Skip to content

Commit fd4ee81

Browse files
committed
feat: add to_v3_profile_dict to User model
1 parent c7c9254 commit fd4ee81

2 files changed

Lines changed: 14 additions & 20 deletions

File tree

libraries/views.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,6 @@
5353
# ── V3 context helpers ─────────────────────────────────────────────────────
5454

5555

56-
def _format_users_for_v3(users, role):
57-
"""Convert User objects to the dict format expected by _user_profile.html."""
58-
result = []
59-
for user in users:
60-
result.append(
61-
{
62-
"name": getattr(user, "display_name", None) or str(user),
63-
"profile_url": None,
64-
"role": role,
65-
"avatar_url": (
66-
user.get_avatar_url() if hasattr(user, "get_avatar_url") else ""
67-
),
68-
"badge_url": None,
69-
}
70-
)
71-
return result
72-
73-
7456
def _format_commit_authors_for_v3(authors, role):
7557
"""Convert CommitAuthor objects to the dict format expected by _user_profile.html."""
7658
result = []
@@ -571,8 +553,11 @@ def get_v3_context_data(self, base_context=None, **kwargs):
571553
]
572554

573555
this_release = (
574-
_format_users_for_v3(base_context.get("authors", []), "Author")
575-
+ _format_users_for_v3(base_context.get("maintainers", []), "Maintainer")
556+
[u.to_v3_profile_dict("Author") for u in base_context.get("authors", [])]
557+
+ [
558+
u.to_v3_profile_dict("Maintainer")
559+
for u in base_context.get("maintainers", [])
560+
]
576561
+ _format_commit_authors_for_v3(
577562
list(base_context.get("top_contributors_release_new", [])),
578563
"New Contributor",

users/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ def get_avatar_url(self):
325325
return ca.avatar_url
326326
return ""
327327

328+
def to_v3_profile_dict(self, role):
329+
return {
330+
"name": self.display_name or str(self),
331+
"profile_url": None,
332+
"role": role,
333+
"avatar_url": self.get_avatar_url(),
334+
"badge_url": None,
335+
}
336+
328337
def get_hq_image_url(self):
329338
# convenience method for templates
330339
if self.hq_image and self.hq_image_render:

0 commit comments

Comments
 (0)