Implement emote gallery model method and refactor view to use it
This commit is contained in:
parent
3070dcb296
commit
1d524a2ca9
3 changed files with 239 additions and 25 deletions
|
|
@ -269,31 +269,7 @@ def emote_gallery_view(request: HttpRequest) -> HttpResponse:
|
|||
Returns:
|
||||
HttpResponse: The rendered emote gallery page.
|
||||
"""
|
||||
emote_benefits: QuerySet[DropBenefit, DropBenefit] = (
|
||||
DropBenefit.objects
|
||||
.filter(distribution_type="EMOTE")
|
||||
.select_related()
|
||||
.prefetch_related(
|
||||
Prefetch(
|
||||
"drops",
|
||||
queryset=TimeBasedDrop.objects.select_related("campaign"),
|
||||
to_attr="_emote_drops",
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
emotes: list[dict[str, str | DropCampaign]] = []
|
||||
for benefit in emote_benefits:
|
||||
# Find the first drop with a campaign for this benefit
|
||||
drop: TimeBasedDrop | None = next(
|
||||
(d for d in getattr(benefit, "_emote_drops", []) if d.campaign),
|
||||
None,
|
||||
)
|
||||
if drop and drop.campaign:
|
||||
emotes.append({
|
||||
"image_url": benefit.image_best_url,
|
||||
"campaign": drop.campaign,
|
||||
})
|
||||
emotes: list[dict[str, str | DropCampaign]] = DropBenefit.emotes_for_gallery()
|
||||
|
||||
seo_context: dict[str, Any] = _build_seo_context(
|
||||
page_title="Twitch Emotes",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue