[charts] Fix chart building
This commit is contained in:
@ -105,7 +105,40 @@ class ScrobbleableListView(ListView):
|
||||
return queryset
|
||||
|
||||
|
||||
class ScrobbleableDetailView(DetailView):
|
||||
class ChartContextMixin:
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
from charts.models import ChartRecord
|
||||
|
||||
obj = context.get("object")
|
||||
if not obj:
|
||||
return context
|
||||
|
||||
media_type_map = {
|
||||
"music.Artist": "artist",
|
||||
"music.Album": "album",
|
||||
"music.Track": "track",
|
||||
"videos.video": "video",
|
||||
"videos.series": "tv_series",
|
||||
"podcasts.podcast": "podcast",
|
||||
"boardgames.boardgame": "board_game",
|
||||
"trails.trail": "trail",
|
||||
"foods.food": "food",
|
||||
"books.book": "book",
|
||||
}
|
||||
|
||||
model_label = f"{obj._meta.app_label}.{obj._meta.model_name}"
|
||||
media_type = media_type_map.get(model_label)
|
||||
|
||||
if media_type:
|
||||
context["charts"] = ChartRecord.objects.filter(
|
||||
**{media_type: obj}, rank__in=[1, 2, 3]
|
||||
)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class ScrobbleableDetailView(ChartContextMixin, DetailView):
|
||||
model = None
|
||||
slug_field = "uuid"
|
||||
|
||||
@ -734,7 +767,6 @@ class ScrobbleStatusView(LoginRequiredMixin, TemplateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
user_scrobble_qs = Scrobble.objects.filter().order_by("-timestamp")
|
||||
progress_plays = user_scrobble_qs.filter(in_progress=True, is_paused=False)
|
||||
|
||||
data["listening"] = progress_plays.filter(
|
||||
Q(track__isnull=False) | Q(podcast_episode__isnull=False)
|
||||
|
||||
Reference in New Issue
Block a user