Add box art to dashboard and add Game.box_art_base_url()
This commit is contained in:
parent
5d572d7b52
commit
b430ce7ae8
3 changed files with 75 additions and 27 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import re
|
||||
from typing import TYPE_CHECKING, ClassVar
|
||||
|
||||
from django.db import models
|
||||
|
|
@ -47,6 +48,23 @@ class Game(models.Model):
|
|||
"""Return all organizations that have drop campaigns for this game."""
|
||||
return Organization.objects.filter(drop_campaigns__game=self).distinct()
|
||||
|
||||
@property
|
||||
def box_art_base_url(self) -> str:
|
||||
"""Return the base box art URL without size suffix.
|
||||
|
||||
Twitch box art URLs often include size suffixes like '-120x160.jpg'.
|
||||
This property returns the base URL without the size suffix.
|
||||
|
||||
Examples:
|
||||
'https://static-cdn.jtvnw.net/ttv-boxart/512710-120x160.jpg'
|
||||
-> 'https://static-cdn.jtvnw.net/ttv-boxart/512710.jpg'
|
||||
"""
|
||||
if not self.box_art:
|
||||
return ""
|
||||
|
||||
# Remove size suffix pattern like '-120x160' from the filename
|
||||
return re.sub(r"-\d+x\d+(\.jpg|\.png|\.jpeg|\.gif|\.webp)$", r"\1", self.box_art)
|
||||
|
||||
|
||||
class Organization(models.Model):
|
||||
"""Represents an organization on Twitch that can own drop campaigns."""
|
||||
|
|
|
|||
|
|
@ -337,6 +337,7 @@ def dashboard(request: HttpRequest) -> HttpResponse:
|
|||
if game_id not in campaigns_by_org_game[org_id]["games"]:
|
||||
campaigns_by_org_game[org_id]["games"][game_id] = {
|
||||
"name": game_name,
|
||||
"box_art": campaign.game.box_art_base_url,
|
||||
"campaigns": [],
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue