[templates] Start redesigning the dashboard
This commit is contained in:
@ -3,9 +3,9 @@ import json
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import pendulum
|
||||
import pytz
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.db.models import Count, Q
|
||||
@ -52,7 +52,6 @@ from scrobbles.tasks import (
|
||||
from scrobbles.utils import (
|
||||
get_long_plays_completed,
|
||||
get_long_plays_in_progress,
|
||||
get_recently_played_board_games,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -107,32 +106,19 @@ class RecentScrobbleList(ListView):
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
user = self.request.user
|
||||
data["date"] = ""
|
||||
if user.is_authenticated:
|
||||
date = self.request.GET.get("date", "")
|
||||
today = timezone.localtime(timezone.now())
|
||||
user_id = self.request.user.id
|
||||
year = today.year
|
||||
month = today.month
|
||||
day = today.day
|
||||
if date:
|
||||
year, month, day = date.split("-")
|
||||
data["date"] = pendulum.parse(date)
|
||||
|
||||
completed_for_user = Scrobble.objects.filter(
|
||||
played_to_completion=True, user=user
|
||||
)
|
||||
data["long_play_in_progress"] = get_long_plays_in_progress(user)
|
||||
data["play_again"] = get_recently_played_board_games(user)
|
||||
data["video_scrobble_list"] = completed_for_user.filter(
|
||||
video__isnull=False
|
||||
).order_by("-timestamp")[:15]
|
||||
|
||||
data["podcast_scrobble_list"] = completed_for_user.filter(
|
||||
podcast_episode__isnull=False
|
||||
).order_by("-timestamp")[:15]
|
||||
|
||||
data["sport_scrobble_list"] = completed_for_user.filter(
|
||||
sport_event__isnull=False
|
||||
).order_by("-timestamp")[:15]
|
||||
|
||||
data["videogame_scrobble_list"] = completed_for_user.filter(
|
||||
video_game__isnull=False
|
||||
).order_by("-timestamp")[:15]
|
||||
|
||||
data["boardgame_scrobble_list"] = completed_for_user.filter(
|
||||
board_game__isnull=False
|
||||
).order_by("-timestamp")[:15]
|
||||
data = data | Scrobble.for_day_dict(user_id, year, month, day)
|
||||
|
||||
data["active_imports"] = AudioScrobblerTSVImport.objects.filter(
|
||||
processing_started__isnull=False,
|
||||
@ -698,45 +684,13 @@ class ChartRecordView(TemplateView):
|
||||
media_type = self.request.GET.get("media", "Track")
|
||||
user = self.request.user
|
||||
params = {}
|
||||
context_data["chart_type"] = self.request.GET.get(
|
||||
"chart_type", "maloja"
|
||||
)
|
||||
context_data["artist_charts"] = {}
|
||||
|
||||
if not date:
|
||||
limit = 20
|
||||
artist_params = {"user": user, "media_type": "Artist"}
|
||||
context_data["current_artist_charts"] = {
|
||||
"today": live_charts(
|
||||
**artist_params, chart_period="today", limit=limit
|
||||
),
|
||||
"week": live_charts(
|
||||
**artist_params, chart_period="week", limit=limit
|
||||
),
|
||||
"month": live_charts(
|
||||
**artist_params, chart_period="month", limit=limit
|
||||
),
|
||||
"year": live_charts(
|
||||
**artist_params, chart_period="year", limit=limit
|
||||
),
|
||||
"all": live_charts(**artist_params, limit=limit),
|
||||
}
|
||||
|
||||
track_params = {"user": user, "media_type": "Track"}
|
||||
context_data["current_track_charts"] = {
|
||||
"today": live_charts(
|
||||
**track_params, chart_period="today", limit=limit
|
||||
),
|
||||
"week": live_charts(
|
||||
**track_params, chart_period="week", limit=limit
|
||||
),
|
||||
"month": live_charts(
|
||||
**track_params, chart_period="month", limit=limit
|
||||
),
|
||||
"year": live_charts(
|
||||
**track_params, chart_period="year", limit=limit
|
||||
),
|
||||
"all": live_charts(**track_params, limit=limit),
|
||||
}
|
||||
|
||||
limit = 14
|
||||
artist = {"user": user, "media_type": "Artist", "limit": limit}
|
||||
# This is weird. They don't display properly as QuerySets, so we cast to lists
|
||||
context_data["chart_keys"] = {
|
||||
|
||||
Reference in New Issue
Block a user