diff --git a/PROJECT.org b/PROJECT.org index ba10636..ea9b720 100644 --- a/PROJECT.org +++ b/PROJECT.org @@ -88,7 +88,7 @@ fetching and simple saving. *** Metadata sources **** Scraper -* Backlog [1/24] :vrobbler:project:personal: +* Backlog [2/25] :vrobbler:project:personal: ** TODO [#C] After transition to linux add curl_cffi as webpage scrapper again :webpages:metadata: ** TODO [#C] Create small utility to clean up tracks scrobbled with wonky playback times :bug:music:scrobbles: :PROPERTIES: @@ -605,6 +605,10 @@ independent of the email flow it was originally creatdd for ** TODO [#B] Is there way to create unique slugs for media instances :media_types: +** DONE [#B] Split up chart page between tables and maloja :charts:templates: +:PROPERTIES: +:ID: 103ab084-2016-cfa4-c677-3c5fdc54cce0 +:END: ** DONE [#A] Fix CI so we don't double run deploys and builds :ci: :PROPERTIES: :ID: 1a93e7cb-b883-aae5-2bd5-fcdd6e16f8ab diff --git a/vrobbler/apps/charts/urls.py b/vrobbler/apps/charts/urls.py index fe05a7b..22c45b5 100644 --- a/vrobbler/apps/charts/urls.py +++ b/vrobbler/apps/charts/urls.py @@ -3,6 +3,7 @@ from charts.views import ( BirdsChartView, ChartDetailView, ChartRecordView, + MalojaChartsView, SpotifyTracksView, ) from django.urls import path @@ -11,6 +12,7 @@ app_name = "charts" urlpatterns = [ path("charts/", ChartRecordView.as_view(), name="charts-home"), + path("charts/maloja/", MalojaChartsView.as_view(), name="maloja-charts"), path("charts/spotify/", SpotifyTracksView.as_view(), name="spotify-tracks"), path("charts/bandcamp/", BandcampTracksView.as_view(), name="bandcamp-tracks"), path("charts/birds/", BirdsChartView.as_view(), name="birds-chart"), diff --git a/vrobbler/apps/charts/views.py b/vrobbler/apps/charts/views.py index d5882eb..9a88541 100644 --- a/vrobbler/apps/charts/views.py +++ b/vrobbler/apps/charts/views.py @@ -159,80 +159,6 @@ class ChartRecordView(TemplateView): context["week"] = current_week context["day"] = current_day - context["chart_keys"] = { - "today": "Today", - "week": "This Week", - "month": "This Month", - "year": "This Year", - "all": "All Time", - } - - context["maloja_charts"] = { - "artist": { - "today": list( - self.get_charts_for_period( - user, "artist", year=year, month=month, day=day, - ) - ), - "week": list( - self.get_charts_for_period( - user, "artist", year=year, week=week, - ) - ), - "month": list( - self.get_charts_for_period( - user, "artist", year=year, month=month, - ) - ), - "year": list( - self.get_charts_for_period(user, "artist", year=year) - ), - "all": list(self.get_charts_for_period(user, "artist")), - }, - "album": { - "today": list( - self.get_charts_for_period( - user, "album", year=year, month=month, day=day, - ) - ), - "week": list( - self.get_charts_for_period( - user, "album", year=year, week=week, - ) - ), - "month": list( - self.get_charts_for_period( - user, "album", year=year, month=month, - ) - ), - "year": list( - self.get_charts_for_period(user, "album", year=year) - ), - "all": list(self.get_charts_for_period(user, "album")), - }, - "tv_series": { - "today": list( - self.get_charts_for_period( - user, "tv_series", year=year, month=month, day=day, - ) - ), - "week": list( - self.get_charts_for_period( - user, "tv_series", year=year, week=week, - ) - ), - "month": list( - self.get_charts_for_period( - user, "tv_series", year=year, month=month, - ) - ), - "year": list( - self.get_charts_for_period(user, "tv_series", year=year) - ), - "all": list(self.get_charts_for_period(user, "tv_series")), - }, - } - # List-group tables default to week-level when no date param (matches active tab) if not date_param: list_year = current_year @@ -510,6 +436,53 @@ class ChartRecordView(TemplateView): } +class MalojaChartsView(ChartRecordView): + """Three maloja-themed image grid widgets (artists, albums, TV series) + with Today/Week/Month/Year/All tabs. Each tab computes its own period + from the current date — no query param needed.""" + + template_name = "charts/maloja_charts.html" + + def get_context_data(self, **kwargs): + context = super(ChartRecordView, self).get_context_data(**kwargs) + user = self.request.user + + now = timezone.now() + if user.is_authenticated: + now = now_user_timezone(user.profile) + today = now.date() + + context["chart_keys"] = { + "today": "Today", + "week": "This Week", + "month": "This Month", + "year": "This Year", + "all": "All Time", + } + + tab_params = { + "today": {"year": today.year, "month": today.month, "day": today.day}, + "week": {"year": today.year, "week": today.isocalendar()[1]}, + "month": {"year": today.year, "month": today.month}, + "year": {"year": today.year}, + } + + maloja_charts = {} + for media_type in ("artist", "album", "tv_series"): + tabs = {} + for key in ("today", "week", "month", "year"): + tabs[key] = list( + self.get_charts_for_period(user, media_type, **tab_params[key]) + ) + tabs["all"] = list( + self.get_charts_for_period(user, media_type) + ) + maloja_charts[media_type] = tabs + + context["maloja_charts"] = maloja_charts + return context + + MEDIA_TYPE_LABELS = { "artist": ("🎤", "Top Artists"), "album": ("💿", "Top Albums"), diff --git a/vrobbler/templates/charts/chart_index.html b/vrobbler/templates/charts/chart_index.html index ddffe3e..bacca6e 100644 --- a/vrobbler/templates/charts/chart_index.html +++ b/vrobbler/templates/charts/chart_index.html @@ -120,7 +120,11 @@ {% endif %} -{% include "scrobbles/_top_charts.html" %} +